3 Replies Latest reply on Feb 13, 2009 4:52 AM by Binesh Gummadi

    Problem with @DataModelSelection

    MA Poitras Newbie
      I am having problems synchronizing the @DataModelSelection with @Datamodel.  When I load the page, the list is displayed but when I select a value, it is not being transfered to the DataModelSelection value.  If I click on a second item in the list I get
      `
      javax.el.PropertyNotFoundException: /forms/contactInfoDetailsSubFrm.xhtml @143,137 value="#{applicationContactSelected.contact.lastName}": Target Unreachable, identifier 'applicationContactSelected' resolved to null
      `

      Here is the the relevant part of the back end bean which is part of a long running conversation.


      `@Stateful
      @Scope(ScopeType.CONVERSATION)
      @Name("contactDetails")
      public class ContactInfoDetailsImpl extends FormCore implements ContactInfoDetails, Serializable {

          @RequestParameter
          Long contactId;
         
          private Boolean isBeingCreated = false;
          private Boolean isBeingEdited = false;
          private Boolean isReadModeRendered;
          private Boolean isAddRowButtonEnabled;
          private boolean isSaveBtnDisabled=true;
          private boolean showAdressMandatoryFields = false;
         
          @DataModel
          private List<ApplicationContact> applicationContacts;

          @DataModelSelection
          private ApplicationContact applicationContactSelected;
              
           
          @Factory("applicationContacts")     
              public void findApplicationContacts() {
               if (applicationContacts==null){
                    applicationContacts=getCurrApplication().getApplicationContacts();
             }
         }
         
           @Create
          public void create() {

               
               //clear any messages
               getFacesMessages().clear();
               
              loadAllPickLists();
           isAddRowButtonEnabled = true;
           isBeingCreated=false;
           isBeingEdited=false;
          }
         

           public String addRowAction() {
           isBeingCreated = true;
           isBeingEdited = false;
           isAddRowButtonEnabled = false;

           ApplicationContact applicationContact = createApplicationContact();   
           applicationContacts.add(applicationContact);
           applicationContactSelected = applicationContact;
             
           return "addRow";
           }
           
           public String editRowAction() {
                isBeingEdited = true;
                isAddRowButtonEnabled = false;
                isBeingCreated = false;
                provinceName = "";
                showAdressMandatoryFields = false;


                return "editRow";
           }

      ........

      }`


      This is how I created the list


      `<h:dataTable value="#{applicationContacts}" var="contactApplicantVar"
           styleClass="view" headerClass="viewHeader"
           rowClasses="viewRows"
           columnClasses="viewCIType,viewCIOrgNames,viewCIBusTel,viewCIResTel">

         <h:column>
          <f:facet name="header">#{messages.ciTypeLbl}</f:facet>
          <h:commandLink id="contactId" action="#{contactDetails.editRowAction()}">

            <h:outputText value="#{contactApplicantVar.contactTypeCode.description.localizedDescription}"/>
          </h:commandLink>
         </h:column>`

      And i reference the selected item for the "Detail" part of the screen like this.


      `<div class="fullWidth">
           <label class="slength2">&#160;&#160;#{messages.ciResTelLbl}&#58;</label>
           <span><h:inputText id="resPhoneID" value="#{applicationContactSelected.contact.residentialTelephone}" maxlength="10" size="11" validator="#{contactDetails.validatePhoneNumber}"/></span>
      </div>

      <div class="fullWidth">
           <label class="slength2">&#160;&#160;#{messages.ciCellPhoneLbl}&#58;</label>
           <span><h:inputText id="cellPhoneID" value="#{applicationContactSelected.contact.cellTelephone}" maxlength="10" size="11" validator="#{contactDetails.validatePhoneNumber}"/></span>
      </div>
      <div class="fullWidth">
           <label class="slength2">&#160;&#160;#{messages.ciFaxLbl}&#58;</label>
           <span><h:inputText id="faxPhoneID" value="#{applicationContactSelected.contact.fax}" maxlength="10" size="11" validator="#{contactDetails.validatePhoneNumber}"/></span>
      </div>`

      And this is the whole xhtml. ( I removed some of the javascript to make it shorter and easier to read.)



      `<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:c="http://java.sun.com/jstl/core"
          xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich">
         
      <fieldset>
           <span class="length330">
                <label><strong class="required"><h:outputText id="isApplicantID" value="*" /></strong>
                               <h:outputText value="#{messages.ciIsTheFirstNationTheApplicantLbl}" />
                </label>
                <span>
                     <h:outputText rendered="#{contactDetails.isFirstNationApplicant}"
                                         value="#{messages.ciYes}" />
                     <h:outputText rendered="#{not contactDetails.isFirstNationApplicant}"
                                         value="#{messages.ciNo}" />
                </span>
           </span>
                                    
           <span class="lllonglength400">
                <label>#{messages.ciFirstNationNameLbl}&#58;</label>
                <span><h:outputText value="#{contactDetails.firstNationName}" /></span>
           </span>
      </fieldset>
                
      <h:messages globalOnly="true" showSummary="true" showDetail="false" layout="table" styleClass="ahMessages" errorStyle="ahMessagesError" fatalStyle="ahMessagesError" infoStyle="ahMessagesInfo" warnStyle="ahMessagesInfo" />
                               
      <a4j:log hotkey="M" />
           <fieldset>

                <legend><h:outputText value="#{messages.ciListOfContactsHeaderLbl}&#160;&#160;"></h:outputText>
                          <h:commandButton onclick="javascript: return checkAuthority(#{contactDetails.authorizationMap['09']});"
                                               action="#{contactDetails.addRowAction()}"
                                                value="#{messages.ciAddContactBtn}"
                                               disabled="#{not contactDetails.isAddRowButtonEnabled or contactDetails.isSaveBtnDisabled}" /></legend>

                <h:dataTable value="#{applicationContacts}" var="contactApplicantVar"
                               styleClass="view" headerClass="viewHeader"
                               rowClasses="viewRows"
                               columnClasses="viewCIType,viewCIOrgNames,viewCIBusTel,viewCIResTel">

                     <h:column>
                          <f:facet name="header">#{messages.ciTypeLbl}</f:facet>
                          <h:commandLink id="contactId" action="#{contactDetails.editRowAction()}">

                                    <h:outputText value="#{contactApplicantVar.contactTypeCode.description.localizedDescription}"/>
                          </h:commandLink>
                     </h:column>

                     <h:column>
                          <f:facet name="header">#{messages.ciOrgLFNameLbl}</f:facet>
                          <h:outputText value="#{contactApplicantVar.application.firstNation.description.localizedDescription}&#160;&#47;&#160;" rendered="#{contactApplicantVar.isApplicant and contactDetails.isFirstNationApplicant}"/>
                          <h:outputText value="#{contactApplicantVar.contact.lastName}" />
                          <h:outputText value="&#160;&#44;&#160;#{contactApplicantVar.contact.firstName}" />
                     </h:column>

                     <h:column>
                          <f:facet name="header">#{messages.ciBusTelLbl}</f:facet>
                          <h:outputText value="#{contactApplicantVar.contact.formattedBusinessTelephone}" />
                     </h:column>

                     <h:column>
                          <f:facet name="header">#{messages.ciResTelLbl}</f:facet>
                          <h:outputText value="#{contactApplicantVar.contact.formattedResidentialTelephone}" />
                     </h:column>

                </h:dataTable>

           </fieldset>

           

           
           <c:choose>
                  <c:when test="${contactDetails.rowEditable}">
                       <fieldset class="noborder">
                            <div>
                          <label><strong class="required">*</strong>#{messages.ciContactTypeLbl}&#58;</label>
                          <span><h:selectOneMenu class="sfont ignoreForHash" value="#{applicationContactSelected.contactTypeCode}"
                                           converter="#{contactDetails.contactTypeCodePickList.converter}"
                                           disabled="#{not contactDetails.isBeingCreated}">
                                         <f:selectItems value="#{contactDetails.contactTypeCodePickList.pickListMap}" />
                                                   <a4j:support event="onchange" action="#{contactDetails.changeContactTypeCodeAction}" reRender="cifna,ciAddr" />
                               </h:selectOneMenu>
                          </span>
                          <span>
                               <h:commandButton id="crudCancelId" action="#{contactDetails.cancelAction}" onclick="dontDisplayWarning()" value="#{messages.cmnCancelBtn}"
                                         rendered="#{contactDetails.isBeingCreated or contactDetails.isBeingEdited}" immediate="true"/>
                          </span>
                          <span><h:commandButton id="crudDeleteId" onclick="javascript: return checkAuthority(#{contactDetails.authorizationMap['09']});"
                                         action="#{contactDetails.removeRowAction}"
                                         rendered="#{contactDetails.isBeingEdited}" value="#{messages.cmnDeleteBtn}"
                                         disabled="#{not contactDetails.isDeleteEnabled or contactDetails.isSaveBtnDisabled}"/>
                          </span>
                          </div>
                     </fieldset>
                     
                     <fieldset class="spfset">
                          <legend><h:outputText value="#{messages.ciContactInfoDetailsTtlLbl}" />
                          </legend>
                          
                          <h:panelGroup id="cifna">
                               
                               <div>
                                    <label class="slength2"><strong class="required">*</strong>#{messages.ciLastNameLbl}&#58;</label>
                                    <span class="sfont"><h:inputText id="lastNameID" value="#{applicationContactSelected.contact.lastName}" maxlength="48" size="30"/></span>
                               </div>
                               <div>
                                    <label class="slength2"><strong class="required">*</strong>#{messages.ciFirstNameLbl}&#58;</label>
                                    <span class="sfont"><h:inputText id="firstNameID" value="#{applicationContactSelected.contact.firstName}" maxlength="25" size="30" /></span>
                               </div>
                               
                               <div class="fullWidth">
                                    <c:choose>
                                         <c:when test="${applicationContactSelected.isApplicant}">
                                              <label class="slength2"><strong class="required">*</strong>#{messages.ciBusTelLbl}&#58;</label>
                                         </c:when>
                                         <c:otherwise>
                                              <label class="slength2">&#160;&#160;#{messages.ciBusTelLbl}&#58;</label>
                                         </c:otherwise>
                                    </c:choose>
                                    <span><h:inputText id="busPhoneID" value="#{applicationContactSelected.contact.businessTelephone}" maxlength="10" size="11" validator="#{contactDetails.validatePhoneNumber}"/></span>
                                    <label>#{messages.ciExtensionLbl}&#58;</label>
                                    <span><h:inputText id="busExtID" value="#{applicationContactSelected.contact.businessTelephoneExtension}" maxlength="10" size="7" validator="#{contactDetails.validateExtension}"/></span>
                               </div>
                               <div class="fullWidth">
                                    <label class="slength2">&#160;&#160;#{messages.ciResTelLbl}&#58;</label>
                                    <span><h:inputText id="resPhoneID" value="#{applicationContactSelected.contact.residentialTelephone}" maxlength="10" size="11" validator="#{contactDetails.validatePhoneNumber}"/></span>
                               </div>
                               
                               <div class="fullWidth">
                                    <label class="slength2">&#160;&#160;#{messages.ciCellPhoneLbl}&#58;</label>
                                    <span><h:inputText id="cellPhoneID" value="#{applicationContactSelected.contact.cellTelephone}" maxlength="10" size="11" validator="#{contactDetails.validatePhoneNumber}"/></span>
                               </div>
                               <div class="fullWidth">
                                    <label class="slength2">&#160;&#160;#{messages.ciFaxLbl}&#58;</label>
                                    <span><h:inputText id="faxPhoneID" value="#{applicationContactSelected.contact.fax}" maxlength="10" size="11" validator="#{contactDetails.validatePhoneNumber}"/></span>
                               </div>                         
                               <div class="fullWidth">
                                    <label class="slength2">&#160;&#160;#{messages.ciEmailLbl}&#58;</label>
                                    <span><h:inputText id="emailID" value="#{applicationContactSelected.contact.emailString}" maxlength="250" size="30" validator="#{contactDetails.validateEmail}"/></span>
                               </div>
                               <div style="margin: 2px 0; width: 100%;">
                                    <c:choose>
                                         <c:when test="${applicationContactSelected.isApplicant}">
                                              <label class="slength2"><strong class="required">*</strong>#{messages.ciLanguageLbl}&#58;</label>
                                         </c:when>
                                         <c:otherwise>
                                              <label class="slength2">&#160;&#160;#{messages.ciLanguageLbl}&#58;</label>
                                         </c:otherwise>
                                    </c:choose>
                                    <span><h:selectOneMenu class="sfont" id="languageID" value="#{applicationContactSelected.contact.languageCode}"
                                                   converter="#{contactDetails.languageCodePickList.converter}" >
                                                   <f:selectItems value="#{contactDetails.languageCodePickList.pickListMap}" />
                                              </h:selectOneMenu>
                                    </span>
                               </div>
                          </h:panelGroup>
                     </fieldset>
                
                </c:when>
           </c:choose>
                     <h:panelGroup id="ciAddr">
           <c:choose>
                  <c:when test="${contactDetails.isAddressVisible}">
                          <fieldset class="spfset">
                               <legend><h:outputText value="#{messages.ciContactAddrDetailsTtlLbl}" /></legend>
                               
                               <div class="fullWidth">
                                    <label class="slength6">&#160;&#160;#{messages.ciStreetNoLbl}&#58;</label>
                                    <span><h:inputText id="streetNumId" value="#{applicationContactSelected.mailingOccupantAddressContact.address.streetNum}" size="7" maxlength="7" validator="#{fieldValidator.validateStreetNumber}"/></span>
                               </div>
                               <div class="fullWidth">
                                    <label class="slength6"><strong class="required"><h:outputText value="*" rendered="#{contactDetails.showAdressMandatoryFields}"></h:outputText></strong>
                                    <h:outputText value="&#160;&#160;" rendered="#{!contactDetails.showAdressMandatoryFields}"></h:outputText>#{messages.ciStreetNameLbl}&#58;</label>
                                    <span><h:inputText id="streetNameId" value="#{applicationContactSelected.mailingOccupantAddressContact.address.streetName}" size="30" maxlength="30" validator="#{fieldValidator.validateStreetName}"/></span>
                               </div>
                               <div style="margin: 1.5px 0; width: 100%;">
                                    <label class="slength6">&#160;&#160;#{messages.ciStreetTypeLbl}&#58;</label>
                                    <span><h:selectOneMenu class="sfont" value="#{applicationContactSelected.mailingOccupantAddressContact.address.streetTypeCode}"
                                                converter="#{contactDetails.streetTypeCodePickList.converter}" >
                                              <f:selectItems value="#{contactDetails.streetTypeCodePickList.pickListMap}" />
                                              </h:selectOneMenu>
                                    </span>
                               </div>
                               <div style="margin: 2px 0 1.5px 0; width: 100%;">
                                    <label class="slength6">&#160;&#160;#{messages.ciStreetDirLbl}&#58;</label>
                                    <span><h:selectOneMenu class="sfont" value="#{applicationContactSelected.mailingOccupantAddressContact.address.streetDirectionCode}"
                                                converter="#{contactDetails.streetDirectionCodePickList.converter}" >
                                              <f:selectItems value="#{contactDetails.streetDirectionCodePickList.pickListMap}" />
                                              </h:selectOneMenu>
                                    </span>
                               </div>
                               <div class="fullWidth">
                                    <label class="slength6">&#160;&#160;#{messages.ciAptUnitNoLbl}&#58;</label>
                                    <span><h:inputText value="#{applicationContactSelected.mailingOccupantAddressContact.address.unitNum}" size="7" maxlength="6" validator="#{fieldValidator.validateAptUnitNumber}"/></span>
                               </div>
                               <div class="fullWidth">
                                    <label class="slength6"><strong class="required"><h:outputText value="*" rendered="#{contactDetails.showAdressMandatoryFields}"></h:outputText></strong>
                                    <h:outputText value="&#160;&#160;" rendered="#{!contactDetails.showAdressMandatoryFields}"></h:outputText>#{messages.ciMunicipalityLbl}&#58;</label>
                                    <span><h:inputText value="#{applicationContactSelected.mailingOccupantAddressContact.address.municipality}"  maxlength="20" size="30" validator="#{fieldValidator.validateMunicipality}"/></span>
                               </div>
                               <div style="margin: 7px 0 5px 0; width: 100%;">
                                    <label class="slength6">&#160;&#160;#{messages.ciProvinceLbl}&#58;</label>
                                    <span><h:outputText id="provinceNameId" value="#{contactDetails.provinceName}"/></span>
                               </div>
                               <div class="fullWidth">
                                    <label class="slength6"><strong class="required"><h:outputText value="*" rendered="#{contactDetails.showAdressMandatoryFields}"></h:outputText></strong>
                                    <h:outputText value="&#160;&#160;" rendered="#{!contactDetails.showAdressMandatoryFields}"></h:outputText>#{messages.ciPostalCodeLbl}&#58;</label>
                                    <span><h:inputText id="pdPostCode" value="#{applicationContactSelected.mailingOccupantAddressContact.address.postalCode}" size="7" maxlength="6" validator="#{fieldValidator.validatePostalCode}">
                                    </h:inputText>
                                    </span>
                               </div>
                          </fieldset>
                </c:when>
           </c:choose>
                     </h:panelGroup>

      <!-- TODO: Refactor to common CrudActionsSubFrm -->
           <div id="crudButtonsSubFrm">
                <div id="cmnButtons">
                     <div class="row">

                          <span>
                               <h:commandButton id="crudSaveId" onclick="javascript: return doPost();"
                                                   action="#{contactDetails.saveUpdateAction}" value="#{messages.cmnSaveBtn}"
                                                   disabled="#{contactDetails.isSaveBtnDisabled}" rendered="#{contactDetails.isBeingCreated or contactDetails.isBeingEdited}"/>
                          </span>
                          
                          <span>
                               <h:commandButton id="crudSaveNextId" onclick="javascript: return doPost();"
                                                   action="#{contactDetails.saveNextAction}" value="#{messages.cmnSaveNextBtn}"
                                                   disabled="#{contactDetails.isSaveBtnDisabled}" />
                          </span>                    

           <!-- If save button is enabled then allow the "exit without save" message to be displayed (if needed) -->
                <ui:fragment rendered="#{!contactDetails.isSaveBtnDisabled}">               
                          <span><h:commandButton id="crudCloseId" action="#{contactDetails.closeAction}" immediate="true"
                               value="#{messages.cmnCloseBtn}" /></span>
                </ui:fragment>
           <!-- If save button is disabled then don't display the "exit without save" message -->
                <ui:fragment rendered="#{contactDetails.isSaveBtnDisabled}">
                          <span><h:commandButton id="crudClose2Id" action="#{contactDetails.closeAction}" onclick="saved = true" immediate="true"
                               value="#{messages.cmnCloseBtn}" /></span>
                </ui:fragment>
                     </div>
                </div>
           </div>
      <!-- End CRUD buttons -->

      </ui:composition>`


      Any idea or suggestions.  It appears that the row value is never set to DataModelSelection.

      Any help would be appreciated
        • 1. Re: Problem with @DataModelSelection
          Cody Lerum Apprentice

          I believe you have to use a form to get the @DataModelSelection working

          • 2. Re: Problem with @DataModelSelection
            MA Poitras Newbie
            Yes, I have the form defined in the template.

            <body onLoad="hashFormData()" onunload="displayPleaseWait()">
            <div id="log"></div>
            <h:form id="formId">
                   
                    <div id="maincontainer">
                   
                            <div id="header">
                                    <ui:insert name="header">
                                            <ui:include src="/common/header.xhtml" />
                                            <div class="ht">
                                                    <span>#{messages.hdMainContentLbl}</span>
                                            </div>
                                    </ui:insert>
                            </div>

                            <div id="sideMenu">
                                    <ui:insert name="sideMenu">
                                            <ui:include src="/common/sideMenu.xhtml" />
                                    </ui:insert>
                            </div>
                   
                            <div id="content">
                                    <div class="contentBody">
                                            <div id="cmnForm">

                                                    <ui:insert name="content">
                                                    </ui:insert>
                                           
                                            </div>
                                            <div class="contentpleasewait" style="position:absolute; top: 100px; left: 300px; width: 250px;height: 100px; display: block; visibility: hidden;" >
                                                    <font style="font-family: Verdana, Arial, Sans-serif; font-size: 12px;font-weight: bold; color: black;">#{messages.infPleaseWait}</font>
                                            </div>
                                    </div>
                            </div>
                           
                            <div id="footer">
                                    <ui:insert name="footer">
                                            <ui:include src="/common/footer.xhtml" />
                                    </ui:insert>
                            </div>
                           
                    </div>
                    <input type="hidden" name="formHashKey" id="formHashKey" value=""/>
            </h:form>

            </body>
            </html>
            </f:view>
            • 3. Re: Problem with @DataModelSelection
              Binesh Gummadi Novice

              I see that your bean is conversational. Where are you starting your conversation and where does it end?


              Add scope to your datamodel and see if it works.


              @DataModel(scope = ScopeType.PAGE)
              private List<ApplicationContact> applicationContacts;