1 Reply Latest reply on Sep 24, 2010 1:14 AM by itays100

    Bean is null after required error message

    itays100 Newbie
      This is my page:


      <h:form id="editManagerForm">
      <s:decorate id="countryField" template="selectField.xhtml">
                     <ui:define name="label">#{messages['text.fund.country']}</ui:define>
                       <a4j:region>                  
                                  <h:selectOneMenu styleClass="clrBackG" label="Country" required="true" requiredMessage="#{messages['text.fund.country.required']}" value="#{management.managerCountry}" converter="countryConverter" id="countryId" >
                                         <a4j:support event="onchange" bypassUpdates="false" reRender="stateAreaId" limitToList="true"/>                                                                                                                                                                                                            
                                        <s:selectItems id="countryListId" value="#{appLists.countryItems}" noSelectionLabel="Please select..." var="country" label="#{country.label}" itemValue="#{country.value}"/>
                                    </h:selectOneMenu>               
                          </a4j:region>
                          </s:decorate>
           
              <a4j:outputPanel id="stateAreaId">
              <s:div rendered="#{not empty management.managerStates}" id="stateDivId">     
                          <s:decorate id="stateField" template="selectField.xhtml">  
                         <ui:define name="label">#{messages['text.fund.state']}</ui:define>   
                                        <h:selectOneMenu styleClass="clrBackG" label="State" required="true" requiredMessage="#{messages['text.fund.state.required']}" value="#{management.managerState}" converter="stateConverter" id="stateId">              
                                            <s:selectItems id="stateListId" value="#{management.managerStates}" noSelectionLabel="Please select..." var="state" label="#{state.label}" itemValue="#{state.value}"/>
                                     </h:selectOneMenu>     
                                     </s:decorate>                        
                       
                   </s:div>
              </a4j:outputPanel> 

      <h:inputHidden value="#{fundManagement.fundManagerCountry}" converter="countryConverter"/>


      <a4j:commandButton id="saveManagerButton" value="Save" action="#{management.saveManagerAction}" reRender="editManagerForm"/>     
        </h:form>


      This is the seam component:
      @Name("management")
      @Scope(ScopeType.CONVERSATION)
      public class ManagmentAction

         @In
         private ApplicationLists appLists;
        
         @In private ManagerDaoHibernateImpl fundDao;
       
         @In(required=false)
         @Out(required=false)
         private Manager manager;
        
         public List<SelectItem> getManagerStates() {
                Country country = this.manager.getCountry();
                if (country == null || country.getStates().size()==0) {
                     return new ArrayList<SelectItem>(0);
                }
                return appLists.getStates(country);
           }     
           
           @Begin
         public void savedManagerAction()
         {
                myDao.saveManager(this.manager);
         }

      }

      When I select country, the state is rendered with states. After that I click on submit.
      There should be a messsage near the states select box indicate it required.
      What I get is that the state list disappear and this is because the manager obj is null.
      I tried to create the constructor and from there create a new manager instance but in this case I got
      the constructor calls also after the "required" error message appear.

      Any idea ?