3 Replies Latest reply on Feb 26, 2009 10:44 AM by waq

    unable to reterive updated value

      Still having a small problem. I need to update one list on the basis of other.

      <h:form>
       State:
       <h:selectOneMenu value="#{Test.state}" id="abc">
       <f:selectItems value="#{Test.states}"/>
       <a4j:support event="onchange" reRender="cityList"/>
       </h:selectOneMenu><br/>
       City:
       <h:selectOneMenu value="#{Test.city}" id="cityList">
       <f:selectItems value="#{Test.cities}"/>
       </h:selectOneMenu>
       <br/>
       Population:
       <h:commandButton id="btn" value="Hello" action="#{Test.res}"/>
       </h:form>


      public class Test {
       private String state;
       private List<SelectItem> states;
       private String city ;
       private List<SelectItem> cities;
      
       public List<SelectItem> getStates() {
       states = new ArrayList<SelectItem>();
       states.add(new SelectItem("<=== SELECT ===>"));
       states.add(new SelectItem("ABC"));
       return states;
       }
      
       public List<SelectItem> getCities() {
       cities = new ArrayList<SelectItem>();
       cities.add(new SelectItem("<=== SELECT ===>"));
       if(this.getState() != null) {
       this.getList();
       }
       return cities;
       }
      
       ...setter & getters
      
       public void res() {
       System.out.println("Button.........."+this.getState() +" "+this.getCity());
       }//end res
      
       public void getList() {
       cities.add(new SelectItem("123"));
       cities.add(new SelectItem("456"));
       }//end getList()
      
      }//end class
      

      Everthing works fine and city list updates properly but when i press button i only get state value and city value returns null.
      I've been having this problem for the last two weeks. So plz correct me where i m doing it wrong.

        • 1. Re: unable to reterive updated value
          nimo22

          do the same as with state:

          
          City:
          <h:selectOneMenu value="#{Test.city}" id="cityList">
          <f:selectItems value="#{Test.cities}"/>
          <a4j:support event="onchange" reRender="cityList"/>
          </h:selectOneMenu>



          • 2. Re: unable to reterive updated value

            Still not working. Its just re-rendering the city list on change event.


            do the same as with state:

            City:
            <h:selectOneMenu value="#{Test.city}" id="cityList">
            <f:selectItems value="#{Test.cities}"/>
            <a4j:support event="onchange" reRender="cityList"/>
            </h:selectOneMenu>


            But what is the need of putting ajax support to the city list as i need to get the values of both list on page submit? Values of both list should be rendered on page submit without ajax support, rite?

            • 3. Re: unable to reterive updated value

              ???