5 Replies Latest reply on Dec 30, 2009 11:21 PM by Jeff Palmer

    DoubleSelect tag?

    Jeff Palmer Newbie

      Hi,


      I'm trying to create a form where the value selected in one select box triggers the values that will be shown in a second select box. Does anyone know what components Seam offers that supports this type of functionality?


        • 1. Re: DoubleSelect tag?
          German Escobar Newbie

          There is not specific components offered by Seam to do this. Just use the a4j:support tag inside your h:selectOneMenu to update the other select box.


          For example:




          ...
          <h:selectOneMenu id="lstCountries" value="...">
             <f:selectItems value="#{countryBean.countries}"/>
             <a4j:support event="onchange" reRender="lstStates" />
          </h:selectOneMenu>
          
          <h:selectOneMenu id="lstStates" value="...">
             <f:selectItems value="#{countryBean.states}"/>
          </h:selectOneMenu>
          ...





          And your bean class could be something like this:




          @Name("countryBean")
          public class CountryBean {
          ...
             public List<SelectItem> getCountries() {
                ...
             }
          
             public List<SelectItem> getStates() {
                // retrieve states that depend on selected country
                ...
             }
          ...
          }





          Hope it helps!

          • 3. Re: DoubleSelect tag?
            Jeff Palmer Newbie

            Rookie question. Still being relatively new to Seam, I'm not sure how I can pass the selected bureau to the bean to filter the divisions based on the selected bureau. Can you expand on your country / state example to show how to retrieve the list of countries based upon the selected state? Thanks.

            • 4. Re: DoubleSelect tag?
              German Escobar Newbie

              One approach is to use the seam s:selectItems tag with the s:convertEntity tag like this:




              <h:selectOneMenu id="lstCountries" value="#{countryBean.country}">
                 <s:selectItems value="#{countryBean.countries}" var="country" label="#{country.name}" noSelectionLabel="Select" />
                 <a4j:support event="onchange" reRender="lstStates"/>
                 <s:convertEntity />
              </h:selectOneMenu>
              
              <h:selectOneMenu id="lstStates" value="#{countryBean.state}">
                 <s:selectItems value="#{countryBean.states}" var="state" label="#{state.name}" />
                 <s:convertEntity />
              </h:selectOneMenu>




              And the bean ...



              @Name("countryBean")
              @Scope(ScopeType.CONVERSATION)
              public class CountryBean {
              
                 @In
                 private EntityManager entityManager;
              
                 private Country country;
                 private State state;
                   
                 public List<Country> getCountries() {
                    return (List<Country>) entityManager.createQuery("select c from Country c").getResultList();
                 }
              
                 public List<State> getStates() {
                    if (country != null) {
                       return (List<State>) entityManager.createQuery("select s from State s where s.country.id = " + country.getId()).getResultList();
                    }
                    return new ArrayList<State>();
                 }
              }



              Tell me if it works.

              • 5. Re: DoubleSelect tag?
                Jeff Palmer Newbie

                The values selected in the first select box is causing the correct values to be displayed in the second select box. The problem I'm now facing is that I'm getting the following error when I select a value from the first select box.


                Error writing 'division' on type org.cityofchicago.water.dma.session.DmaCaseCriteria


                My DmaCaseCriteria class has a setter for division, so I'm not sure why this is happening?