0

I have this composite component that based on what is selected in a drop down(STREET, PO BOX) renders either another composite component streetAddressUpdate or postalBoxAddressUpdate. Here is the code

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:cc="http://java.sun.com/jsf/composite"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:tad="http://java.sun.com/jsf/composite/tmr/ad"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:tmi="http://java.sun.com/jsf/composite/tmr/mi">

<!-- INTERFACE -->
<cc:interface>
    <cc:attribute
        name="title"
        default="Postal address" />
    <cc:attribute
        name="postalAddress"
        type="qdtmr.comp.cbui.address.fieldmodel.PostalAddress"
        default="#{addressUpdate.postalAddress}"
        required="true" />
 </cc:interface>
<cc:implementation>
<ol class="questions">

    <!-- Postal address type -->
    <li><h:outputLabel for="postalAddressType">
            <span class="label">#{tcum.postalAddressType}</span>
        </h:outputLabel> <p:selectOneMenu
            id="postalAddressType"
            value="#{cc.attrs.postalAddress.postalAddressType}"
            valueChangeListener="#{addressUpdate.changePostalAddress}">
            <f:selectItems value="#{addressController.postalAddressTypesList}" />
            <p:ajax
                update=":#{cc.clientId}:postalAddressPanel, :#{cc.clientId}:poBoxPanel" />
        </p:selectOneMenu></li>

    <p:outputPanel id="postalAddressPanel">
        <ui:fragment rendered="#{cc.attrs.postalAddress.postalAddressType == 'STREET'}">
            <tad:streetAddressUpdate
                streetAddress="#{cc.attrs.postalAddress.postalStreetAddress}"
                title="" />
        </ui:fragment>
    <p:outputPanel id="poBoxPanel">
        <ui:fragment rendered="#{cc.attrs.postalAddress.postalAddressType == 'POBOX'}">
            <tad:postalBoxAddressUpdate
                postalBoxAddress="#{cc.attrs.postalAddress.postalBoxAddress}" />
        </ui:fragment>
    </p:outputPanel>
</ol>
</cc:implementation>
</html>

The thing that is confusing me is that if I take out the ui:fragment tag, my values on the page make their way back to the postalStreetAddress/postalBoxAddress model beans, but with the ui:fragment in their, my values do not end up making to the postalStreetAddress/postalBoxAddress.

The reason I have the ui:fragment is because depending on the postalAdressType either the postalBoxAddressUpdate composite component will be used or the postalStreetAddressUpdate component will be used.

Any help will be greatly appreciated. I suspect its the ui:fragment

EDIT: I checked up taking out the ui:fragment and it does seem to be the culprit. I would really like to understand whats happening

Sekhon
  • 108
  • 1
  • 10
  • So, the bean is not in the view scope? – BalusC Jul 31 '13 at 03:19
  • Hi BalusC, Thanks for taking the time. No, the bean is RequestScoped – Sekhon Jul 31 '13 at 03:55
  • Apologies, but both the PostalStreetAddress and PostalBoxAddress beans are in request scope. I can log the values and see that they are available in the APPLY_REQUEST RequestParameterMap, but the values never make into the beans where they are needed for INVOKE_APPLICATION . This a form submission – Sekhon Jul 31 '13 at 04:13
  • Put bean in view scope. If that works, your request scoped model preserving logic is broken. See also point 5 of http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 – BalusC Jul 31 '13 at 11:44
  • Click the link for explanation. – BalusC Jul 31 '13 at 12:18
  • Hi BalusC, Could you explain what you mean by "request scoped model preserving logic"? Also thanks for the great Thread. Could you also point to some good industry practices or article particularly around how to avoiding using SessionScoped and something that explains ViewScoped well. – Sekhon Jul 31 '13 at 12:34
  • The code which you have in bean's (post)constructor which is responsible for among others outcome of `rendered` attribute. As to practices, checkout http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html – BalusC Jul 31 '13 at 12:36
  • Thank you BalusC!! Fixed my issue. In APPLY_REQUEST, the rendered, would evaluate to false. I have bookmarked the page. Do you have any other collection of page links that would come in handy for someone who has started out in JSF2 – Sekhon Aug 01 '13 at 01:14
  • Sure, https://jsf.zeef.com/bauke.scholtz – BalusC Aug 01 '13 at 01:28

0 Answers0