Skip to Main Content

cascade dropdown on selection of one dropdown

anemdhanaAug 16 2013


I have customerController annotated as @Model, StateListProducer being @RequestScoped and the following is my view.

on select of state dropdown, need to populate city dropdown by ajax call, I were successful using <f:ajax /> tag, but problem is when submitting the form, the dropdown value for city is being sent as invalid though I select right value and hence the error was throw 'value is invalid for city'.

     <div class="message"><h:message for="state" errorClass="invalid" /></div>
     <span><h:outputLabel for="state" value="#{msg['customer.state']}:" /></span>
     <h:selectOneMenu value="#{newCustomer.address[0]}" id="state" requiredMessage="#{msg['field.required']}">
          <f:selectItem itemLabel="-- Select a State -- " />
          <f:selectItems value="#{states}" var="state_"
               itemValue="#{}" itemLabel="#{state_.value}" />
          <f:validateRequired />
          <f:ajax event="change" listener="#{customerController.refreshCitiesBySelectedState()}" render="city" onevent="showLoadingIndicator"/>

     <div class="message"><h:message for="city" errorClass="invalid" /></div>
     <span><h:outputLabel for="city" value="#{msg['']}:" /></span>
     <h:selectOneMenu value="#{newCustomer.address[0]}" id="city" requiredMessage="#{msg['field.required']}">
          <f:selectItem itemLabel="-- Select a city -- "/>
          <f:selectItems value="#{cities}" var="city_"
               itemValue="#{}" itemLabel="#{city_.value}" />
          <f:validateRequired />

Pls correct me if I have missed anything..

Post Details
Added on Aug 16 2013