2 Replies Latest reply on Jun 13, 2008 3:31 PM by thetoad

    a4j:support on selectOneMenu

    thetoad

      Hi everybody,

      I have a doubt on using a4j:suport properties in components selectOneMenus.
      I have two of those components in my interface: one that lists contries and other that list states.
      In the first moment the selectOneMenu State is not showed.
      When the user selects one country in the selectOneMenu Country, the component State should be showed and the attribute country of my backing bean should be updated.
      I'm starting on the richfaces, and it seems to me that I'll have to use the a4j:support, but I have no idea about how I can do it... can anyone help me?


      Backing bean:

      public class User {
       private ArrayList<SelectItem> countries;
       private ArrayList<SelectItem> states;
       private String country;
       private String state;
      
       public String getCountry() {
       return country;
       }
      
       public void setCountry(String country) {
       this.country = country;
       }
      
       public ArrayList<SelectItem> getCountries() {
       return countries;
       }
      
       public ArrayList<SelectItem> getStates() {
       return states;
       }
      
       public User() {
       countries = new ArrayList<SelectItem>();
       countries.add(new SelectItem(1, "Brasil"));
       countries.add(new SelectItem(2, "Holanda"));
      
       states = new ArrayList<SelectItem>();
       states.add(new SelectItem(1, "Bahia"));
       states.add(new SelectItem(2, "Rio de Janeiro"));
       }
      
       public String getState() {
       return state;
       }
      
       public void setState(String state) {
       this.state = state;
       }
      
       public boolean isStateRendered() {
       if(country == "Brasil") return true;
       else return false;
       }
      }
      


      Jsf page:
      <h:selectOneMenu id="selectOneCountry" value="#{User.country}">
       <a4j:support event="onchange" reRender="selectState" />
       <f:selectItems value="#{User.countries}"/>
      </h:selectOneMenu>
      
      <h:selectOneMenu id="selectState" rendered="#{User.stateRendered}" value="#{User.state}">
       <f:selectItems value="#{User.states}"/>
      </h:selectOneMenu>
      


      I'm using the richfaces 3.1.3 and the jsf ri 1.2

      Thanks!