5 Replies Latest reply on Aug 6, 2008 7:15 AM by System Administrator

    SFSB setters not being called

    System Administrator Expert

      I have two SFSB backing beans for a facelet.  The facelet has other facelets embedded in it.


      When I fill out the form and click the submit button, the setter methods on SFSB A is not being called until after the backing action method associated with the submit button execs.  The setter methods on SFSB B are being called.  Those setter methods are associated with the same component for the action/submit button.


      I know that you can use entity classes and their setter/getter methods with form input in facelets.  so anybody know why SFSB A's setter methods are not being called?  I even tried changing adding Scope(ScopeType.SESSION) to SFSB A to make sure it is not destroyed.


      How can I force the setter methods on two different SFSB's associated with a facelet to be called when I submit a single form??

        • 1. Re: SFSB setters not being called
          System Administrator Expert

          Also, SFSB B is suffering from bloating session anti-pattern (1000 lines of code) so I only posted a small portion of it. 


          So a general best practice or strategy in real-world implementations/cases would be helpful regarding more than one backing bean for a form/facelet.


          SFSB B (setters are being called right before action method execution):


          @Stateful
          @Name("CreateAccount")
          public class CreateAccountBean implements CreateAccount
          {
          
            @Logger
            private Log log;
          
            //@PersistenceContext
            @In
            EntityManager entityManager;
          
            @In
            FacesMessages facesMessages;
            
            @In(create=true)
            CreateHouseRecord createHouseRecordClient;
            
            @In(create=true)
            HouseAddress houseAddress;
          
           ...
          }



          SFSB A (setter methods need to be called before action method on SFSB B execs):


          package com.cox.coxbusinessaccountcreation;
          
          import javax.ejb.Remove;
          import javax.ejb.Stateful;
          
          import org.hibernate.validator.Length;
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.Destroy;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Scope;
          
          @Stateful
          @Name("houseAddress")
          public class HouseAddressBean implements HouseAddress
          {
          
            private Long streetNumber;
            private String preDirectional;
            private String streetName;
            private String postDirectional;
            private String unit;
            private String city;
            private String state;
            private Integer zipCode;
            private String streetAddress;
            private Integer companyNumber;
            private Integer divisionNumber;
            private Integer franchiseId;
            private Integer houseNumber;
            private String houseStatus;
            private String billTypeCode;
            private String houseAddressable;
            private String auditCheckCode;
          
            public Long getStreetNumber()
            {
              return streetNumber;
            }
          
            public void setStreetNumber(Long streetNumber)
            {
              this.streetNumber = streetNumber;
            }
          
            public String getPreDirectional()
            {
              return preDirectional;
            }
          
            public void setPreDirectional(String preDirectional)
            {
              this.preDirectional = preDirectional;
            }
          
            public String getStreetName()
            {
              return streetName;
            }
          
            public void setStreetName(String streetName)
            {
              this.streetName = streetName;
            }
          
            public String getPostDirectional()
            {
              return postDirectional;
            }
          
            public void setPostDirectional(String postDirectional)
            {
              this.postDirectional = postDirectional;
            }
          
            public String getUnit()
            {
              return unit;
            }
          
            public void setUnit(String unit)
            {
              this.unit = unit;
            }
          
            public String getCity()
            {
              return city;
            }
          
            public void setCity(String city)
            {
              this.city = city;
            }
          
            public String getState()
            {
              return state;
            }
          
            public void setState(String state)
            {
              this.state = state;
            }
          
            public Integer getZipCode()
            {
              return zipCode;
            }
          
            public void setZipCode(Integer zipCode)
            {
              this.zipCode = zipCode;
            }
          
            public String getStreetAddress()
            {
              return streetAddress;
            }
          
            public void setStreetAddress(String streetAddress)
            {
              this.streetAddress = streetAddress;
            }
          
            public Integer getCompanyNumber()
            {
              return companyNumber;
            }
          
            public void setCompanyNumber(Integer companyNumber)
            {
              this.companyNumber = companyNumber;
            }
          
            public Integer getDivisionNumber()
            {
              return divisionNumber;
            }
          
            public void setDivisionNumber(Integer divisionNumber)
            {
              this.divisionNumber = divisionNumber;
            }
          
            public Integer getFranchiseId()
            {
              return franchiseId;
            }
          
            public void setFranchiseId(Integer franchiseId)
            {
              this.franchiseId = franchiseId;
            }
          
            public Integer getHouseNumber()
            {
              return houseNumber;
            }
          
            public void setHouseNumber(Integer houseNumber)
            {
              this.houseNumber = houseNumber;
            }
          
            public String getHouseStatus()
            {
              return houseStatus;
            }
          
            public void setHouseStatus(String houseStatus)
            {
              this.houseStatus = houseStatus;
            }
          
            public String getBillTypeCode()
            {
              return billTypeCode;
            }
          
            public void setBillTypeCode(String billTypeCode)
            {
              this.billTypeCode = billTypeCode;
            }
          
            public String getHouseAddressable()
            {
              return houseAddressable;
            }
          
            public void setHouseAddressable(String houseAddressable)
            {
              this.houseAddressable = houseAddressable;
            }
          
            public String getAuditCheckCode()
            {
              return auditCheckCode;
            }
          
            public void setAuditCheckCode(String auditCheckCode)
            {
              this.auditCheckCode = auditCheckCode;
            }
          
            public void houseAddress()
            {
            }
          
            public void HouseAddress()
            {
            }
          
            public void HouseAddress(
                Long streetNumber,
                String preDirectional,
                String streetName,
                String postDirectional,
                String unit,
                String city,
                String state,
                Integer zipCode,
                String streetAddress,
                Integer companyNumber,
                Integer divisionNumber,
                Integer franchiseId,
                Integer houseNumber,
                String houseStatus,
                String billTypeCode,
                String houseAddressable,
                String auditCheckCode)
            {
              this.streetNumber = streetNumber;
              this.preDirectional = preDirectional;
              this.streetName = streetName;
              this.postDirectional = postDirectional;
              this.unit = unit;
              this.city = city;
              this.state = state;
              this.zipCode = zipCode;
              this.streetAddress = streetAddress;
              this.companyNumber = companyNumber;
              this.divisionNumber = divisionNumber;
              this.franchiseId = franchiseId;
              this.houseNumber = houseNumber;
              this.houseStatus = houseStatus;
              this.billTypeCode = billTypeCode;
              this.houseAddressable = houseAddressable;
              this.auditCheckCode = auditCheckCode;
            }
          
            //@Length(max = 10, message = "Maximum 10 characters")
            @Destroy
            @Remove
            public void destroy()
            {
            }
          }
          



          Main facelet:


          <!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:h="http://java.sun.com/jsf/html"
                          xmlns:rich="http://richfaces.org/rich"
                          xmlns:a="http://richfaces.org/a4j"
                          template="layout/template1column.xhtml">
                                 
          <ui:define name="mainContent">
          
              <h:messages globalOnly="true" styleClass="message"/>
              
                  <rich:panel id="panelParentCreateHouseRecord">
                      <f:facet name="header">Create House Record</f:facet>
          
                      <rich:modalPanel id="modalPanelAddressMatch" minHeight="200" minWidth="450"
                          height="200" width="600" zindex="2000">
                          <f:facet name="header">
                              <h:outputText value="Address search results" />
                          </f:facet>
                          <f:facet name="controls">
                              <h:panelGroup>
                                  <h:graphicImage value="/img/close.png" style="cursor:pointer" id="hidelinkAddressMatch"/>
                                  <rich:componentControl for="modalPanelAddressMatch" attachTo="hidelinkAddressMatch" operation="hide" event="onclick"/>
                              </h:panelGroup>
                          </f:facet>
                                <h:panelGrid columns="5">
                                    <ui:include src="AddressMatch.xhtml" />
                                </h:panelGrid>
                      </rich:modalPanel>
                        
                         <rich:modalPanel id="modalPanelAddressMatchResults" minHeight="200" minWidth="450"
                              height="200" width="600" zindex="2000">
                          <f:facet name="header">
                              <h:outputText value="Address search results" />
                          </f:facet>
                          <f:facet name="controls">
                              <h:panelGroup>
                                  <h:graphicImage value="/img/close.png" style="cursor:pointer" id="hidelinkAddressMatchResults"/>
                                  <rich:componentControl for="modalPanelAddressMatchResults" attachTo="hidelinkAddressMatchResults" operation="hide" event="onclick"/>
                              </h:panelGroup>
                          </f:facet>
                          <ui:include src="AddressMatchResults.xhtml" />
                         </rich:modalPanel>
          
                      <rich:panel id="panelCreateHouseRecord">
                            <ui:include src="CreateHouseRecord.xhtml" />
                      </rich:panel>
                                       
                      <rich:modalPanel id="modalPanelSubmitResults" minHeight="200" minWidth="450"
                          height="200" width="500" zindex="2000">
                          <f:facet name="header">
                              <h:outputText value="Create Account Results" />
                          </f:facet>
                          <f:facet name="controls">
                              <h:panelGroup>
                                  <h:graphicImage value="/img/close.png" onclick="window.location='createAccount.xhtml'" style="cursor:pointer" id="hidelinkSubmit"/>
                              </h:panelGroup>
                          </f:facet>
                          <ui:include src="CreateHouseRecordResults.xhtml" />
                      </rich:modalPanel>
                           
                  </rich:panel>
          
                  <script>
                  //<![CDATA[
                  jQuery(document).ready
                  (function()
                    {
                        Richfaces.showModalPanel('modalPanelAddressMatch');
                    }
                  );
                  //]]>
                  </script>
          
          </ui:define>
          
          </ui:composition>
          



          facelet whose setters are not executing:


          <!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:h="http://java.sun.com/jsf/html"
                          xmlns:rich="http://richfaces.org/rich"
                          xmlns:a="http://richfaces.org/a4j">
                                 
              <h:form id="formAddressMatchResults">
                      <h:outputText value="No records returned." rendered="#{empty houseAddresses}"/>
                      <h:dataTable value="#{houseAddresses}"
                          var="houseAddress"
                          styleClass="SearchResults"
                          headerClass="SearchResultsHeader"
                          rowClasses="SearchResultsRow,SearchResultsAlternatingRow"
                          cellspacing="0"
                          columnClasses="SearchResultsTd"
                          rendered="#{not empty houseAddresses}">
                          <h:column>
                              <a:commandLink id="commandLinkSearchSelectRow" action="#{CreateAccount.selectAddress}" reRender="panelCreateHouseRecord" value="Select" oncomplete="Richfaces.hideModalPanel('modalPanelAddressMatchResults')"/>
                          </h:column>
                          <h:column id="streetNumber">
                              <f:facet name="header"><h:outputText value="Street Number" /></f:facet>
                              #{houseAddress.streetNumber}
                          </h:column>
                          <h:column id="preDirectional">
                              <f:facet name="header"><h:outputText value="Pre Directional" /></f:facet>
                              #{houseAddress.preDirectional}
                          </h:column>
                          <h:column id="streetName">
                              <f:facet name="header"><h:outputText value="Street Name" /></f:facet>
                              #{houseAddress.streetName}
                          </h:column>
                          <h:column id="postDirectional">
                              <f:facet name="header"><h:outputText value="Post Directional" /></f:facet>
                              #{houseAddress.postDirectional}
                          </h:column>
                          <h:column id="unit">
                              <f:facet name="header"><h:outputText value="Unit" /></f:facet>
                              #{houseAddress.unit}
                          </h:column>
                          <h:column id="city">
                              <f:facet name="header"><h:outputText value="City" /></f:facet>
                              #{houseAddress.city}
                          </h:column>
                          <h:column id="state">
                              <f:facet name="header"><h:outputText value="State" /></f:facet>
                              #{houseAddress.state}
                          </h:column>
                          <h:column id="zipCode">
                              <f:facet name="header"><h:outputText value="Zip Code" /></f:facet>
                              #{houseAddress.zipCode}
                          </h:column>
                          <h:column id="companyNumber">
                              <f:facet name="header"><h:outputText value="Company Number" /></f:facet>
                              #{houseAddress.companyNumber}
                          </h:column>
                          <h:column id="divisionNumber">
                              <f:facet name="header"><h:outputText value="Division Number" /></f:facet>
                              #{houseAddress.divisionNumber}
                          </h:column>
                          <h:column id="franchiseId">
                              <f:facet name="header"><h:outputText value="Franchise Id" /></f:facet>
                              #{houseAddress.franchiseId}
                          </h:column>
                          <h:column id="houseStatus">
                              <f:facet name="header"><h:outputText value="House Status" /></f:facet>
                              #{houseAddress.houseStatus}
                          </h:column>
                          <h:column id="billTypeCode">
                              <f:facet name="header"><h:outputText value="Bill Type Code" /></f:facet>
                              #{houseAddress.billTypeCode}
                          </h:column>
                          <h:column id="houseAddressable">
                              <f:facet name="header"><h:outputText value="House Addressable" /></f:facet>
                              #{houseAddress.houseAddressable}
                          </h:column>
                      </h:dataTable>
              </h:form>
              
          </ui:composition>
          



          Facelet whose setters are executing:


          <!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:h="http://java.sun.com/jsf/html"
                          xmlns:rich="http://richfaces.org/rich"
                          xmlns:a="http://richfaces.org/a4j">
                                 
              <h:form id="formCreateAccountRecord">
          
                      <fieldset>
                           <legend>Address</legend>
                           
                           <h:panelGrid columns="5">
                                <s:decorate id="valueDecoration1" template="/layout/edit.xhtml">
                                    <ui:define name="label">Street Number</ui:define><br/>
                                    <h:inputText id="inputStreetNumber" maxlength="9" required="true"
                                                 value="#{CreateAccount.streetNumber}"/>
                                </s:decorate>
                    
                                  <s:decorate id="valueDecoration2" template="/layout/edit.xhtml">
                                    <ui:define name="label">Pre Directional</ui:define><br/>
                                    <h:inputText id="inputPreDirectional" maxlength="2" required="false"
                                                 value="#{CreateAccount.preDirectional}"/>
                                </s:decorate>            
                    
                                   <s:decorate id="valueDecoration3" template="/layout/edit.xhtml">
                                    <ui:define name="label">Street Name</ui:define><br/>
                                    <h:inputText id="inputStreetName" maxlength="20" required="true"
                                                 value="#{CreateAccount.streetName}"/>
                                </s:decorate>     
                    
                                  <s:decorate id="valueDecoration4" template="/layout/edit.xhtml">
                                    <ui:define name="label">Street Type</ui:define><br/>
                                    <h:inputText id="inputStreetType" maxlength="2" required="false"
                                                 value="#{CreateAccount.streetType}"/>
                                </s:decorate>         
                    
                                  <s:decorate id="valueDecoration5" template="/layout/edit.xhtml">
                                    <ui:define name="label">Post Directional</ui:define><br/>
                                    <h:inputText id="inputPostDirectional" maxlength="2" required="false"
                                                 value="#{CreateAccount.postDirectional}"/>
                                </s:decorate>                                 
                    
                                  <s:decorate id="valueDecoration9" template="/layout/edit.xhtml">
                                    <ui:define name="label">Unit</ui:define><br/>
                                    <h:inputText id="inputUnit" maxlength="6" required="false"
                                                 value="#{CreateAccount.unit}"/>
                                </s:decorate>     
                    
                                  <s:decorate id="valueDecoration10" template="/layout/edit.xhtml">
                                    <ui:define name="label">City</ui:define><br/>
                                    <h:inputText id="inputCity" maxlength="25" required="true"
                                                 value="#{CreateAccount.city}"/>
                                </s:decorate>     
                    
                                  <s:decorate id="valueDecoration11" template="/layout/edit.xhtml">
                                    <ui:define name="label">State</ui:define><br/>
                                    <h:inputText id="inputState" disabled="true" maxlength="2" required="true"
                                                 value="#{CreateAccount.state}"/>
                                </s:decorate>     
                    
                                  <s:decorate id="valueDecoration12" template="/layout/edit.xhtml">
                                    <ui:define name="label">Zip5</ui:define><br/>
                                    <h:inputText id="inputZip5" maxlength="5" required="true"
                                                 value="#{CreateAccount.zip5}"/>
                                </s:decorate>     
                    
                                  <s:decorate id="valueDecoration14" template="/layout/edit.xhtml">
                                    <ui:define name="label">Grid</ui:define><br/>
                                    <h:inputText id="inputGrid" maxlength="15" required="false"
                                                 value="#{CreateAccount.grid}"/>
                                </s:decorate>     
                    
                                  <s:decorate id="valueDecoration15" template="/layout/edit.xhtml">
                                    <ui:define name="label">Node</ui:define><br/>
                                    <h:inputText id="inputNode" maxlength="5" required="false"
                                                 value="#{CreateAccount.node}"/>
                                </s:decorate>
                    
                                  <s:decorate id="valueDecoration23" template="/layout/edit.xhtml">
                                    <ui:define name="label">Company Number</ui:define><br/>
                                    <h:inputText required="false" disabled="true" id="inputCompany" value="#{CreateAccount.company}"/>
                                </s:decorate>
                                
                                  <s:decorate id="valueDecoration24" template="/layout/edit.xhtml">
                                    <ui:define name="label">Division Number</ui:define><br/>
                                    <h:inputText required="false" disabled="true" id="inputDivision" value="#{CreateAccount.division}"/>
                                </s:decorate>   
                    
                                 <s:decorate id="valueDecoration25" template="/layout/edit.xhtml">
                                    <ui:define name="label">Franchise Number</ui:define><br/>
                                    <h:inputText id="inputFranchise" disabled="true" maxlength="3" required="false"
                                                 value="#{CreateAccount.franchise}"/>
                                </s:decorate>   
                                
                                <s:decorate id="valueDecoration6" template="/layout/edit.xhtml">
                                    <ui:define name="label">Business Name</ui:define><br/>
                                    <h:inputText id="inputBusinessName" maxlength="25" required="false"
                                                 value="#{CreateAccount.businessName}"/>
                                </s:decorate> 
                                
                              </h:panelGrid>
                         </fieldset>
          
                      <fieldset>
                      <legend>Serviceability</legend>     
                           <s:decorate id="valueDecoration16" template="/layout/edit.xhtml">
                               <h:selectManyCheckbox layout="pageDirection" value="#{CreateAccount.selectedServices}" id="selectManyCheckboxServiceableStatus">
                                    <s:selectItems id="selectManyCheckboxOptions" value="#{services}" var="service" label="#{service.name}"/>
                                  <s:convertEntity/>
                               </h:selectManyCheckbox>
                           </s:decorate>   
                         </fieldset>
                         
                      <fieldset>
                      <legend>General</legend>
                           <h:panelGrid columns="3">
                                  <s:decorate id="valueDecoration32" template="/layout/edit.xhtml">
                                    <ui:define name="label">Headend</ui:define><br/>
                                    <h:inputText id="inputHeadend" maxlength="2" required="true"
                                                 value="#{CreateAccount.headend}"/>
                                </s:decorate>
                    
                                  <s:decorate id="valueDecoration35" template="/layout/edit.xhtml">
                                    <ui:define name="label">Primary Locator</ui:define><br/>
                                    <h:inputText id="inputPrimaryLocatorCode" maxlength="2" required="true"
                                                 value="#{CreateAccount.primaryLocatorCode}"/>
                                </s:decorate>
                    
                                  <s:decorate id="valueDecoration36" template="/layout/edit.xhtml">
                                    <ui:define name="label">Secondary Locator</ui:define><br/>
                                  <h:inputText id="inputSecondaryLocatorCode" maxlength="2" required="true"
                                                 value="#{CreateAccount.secondaryLocatorCode}"/>
                                </s:decorate>
                           </h:panelGrid>
                         </fieldset>
                         
                    <br/>
                    <div class="actionButtons">
                        <a:commandButton id="commandButtonCreateAccount" value="Create Account" 
                                action="#{CreateAccount.createAccount}" reRender="modalPanelSubmitResults" oncomplete="Richfaces.showModalPanel('modalPanelSubmitResults')"/>                 
                    </div>
                    <br/>
                    <div class="actionButtons">
                        <s:button id="buttonClearForm" view="/main/CreateAccount.xhtml" value="Reset Form" propagation="none"></s:button>     
                    </div>
                    <br/>
                    <div class="actionButtons">
                        <s:button id="buttonSearch" onclick="Richfaces.showModalPanel('modalPanelAddressMatch')" value="Search"></s:button>     
                    </div>            
              </h:form>
              
          </ui:composition>
          



          • 2. Re: SFSB setters not being called
            Daniel Hinojosa Master

            the facelet whose setters are not executing, doesn't have any <h:input*>: fields so of course nothing sets, was that a posting mistake?... the other thing I noticed is that you have multiple <h:form>s when it all finally comes together. You need everything under one, in order for it to work right. Unless I am missing something.

            • 3. Re: SFSB setters not being called
              System Administrator Expert

              Sorry, you're right it was my mistake.  This is not my code (my coworker's code) and I'm helping out.  There are several facelets embedded in the main facelet.


              The problem is that the setCompany() and setDivision() setter methods are not coded in the local interface or the CreateAccountBean SFSB implementation class.


              So apparently JSF/Seam don't throw/log an exception when it can't find the setter method(s) during the update model values phase - at least I didn't see one in the console or server.log.


              So one last question I have is the following:


              if an <h:inputText> has is disabled as follows:


              <h:inputText required="false" disabled="true" id="inputCompany" value="#{CreateAccount.company}"/>



              then will the setter method still get called?  I have a feeling it will but just wondering...


              • 4. Re: SFSB setters not being called
                Daniel Hinojosa Master

                Without looking it up, I am betting no.

                • 5. Re: SFSB setters not being called
                  System Administrator Expert

                  I tested it, you're right, the setter doesn't get called in a case like this:


                  <h:inputText required="false" disabled="true" id="inputCompany" value="#{CreateAccount.company}"/>