-1

I want to create a JSF application. In the application the user will have two drop downs.

If a user selects the country Mexico / value 3 from the first drop down then he is required to choose the option Cancun / value 6 from the multiselect

I have added the binding , required attribute for multiSelectListbox but they are not triggered when the drop down is selected

<h:form>
<p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true" />

<p:panel header="Tranfer Destination" style="margin-bottom:10px;">
<h:panelGrid columns="2" cellpadding="5">
    <p:outputLabel for="country" value="Country: " />
    <p:selectOneMenu id="country" value="#{dropdownView.country}" style="width:150px" required="true" binding="#{country}">
        <f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
        <f:selectItems value="#{dropdownView.countries}" />
    </p:selectOneMenu>

    <p:outputLabel for="city" value="City: " />
    <p:multiSelectListbox id="city" value="#{dropdownView.city}" style="width:150px" required="#{not empty param[country.6]}">
        <f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
        <f:selectItem itemLabel="New York" itemValue="1"> </f:selectItem>
        <f:selectItem itemLabel="Chicago" itemValue="2"> </f:selectItem>
        <f:selectItem itemLabel="Seattle"  itemValue="3"> </f:selectItem>
        <f:selectItem itemLabel="Toronto" itemValue="4"> </f:selectItem>
        <f:selectItem itemLabel="Ontario" itemValue="5"> </f:selectItem>
        <f:selectItem itemLabel="Cancun" itemValue="6"> </f:selectItem>
        <f:selectItem itemLabel="Tijuana" itemValue="7"> </f:selectItem>
    </p:multiSelectListbox>
 </h:panelGrid>

<p:separator />

<p:commandButton value="Submit" update="msgs" action="#{dropdownView.displayLocation}" icon="pi pi-check" />
</p:panel>
</h:form>

The option Cancun / value 6 is required from the second drop down only If the user selects the country Mexico / value 3 from the first drop down

Noah
  • 68
  • 1
  • 7
heidi
  • 11
  • 2
  • I have a deja-vu... https://stackoverflow.com/questions/60476673/make-a-multiselect-drop-downvalue-required-based-in-the-input-of-previous-psele – Kukeltje Mar 04 '20 at 18:12

1 Answers1

0

After selecting first drop-down, you need to update <p:multiSelectListbox id="city"/>.

<p:selectOneMenu id="country" 
                 value="#{dropdownView.country}" 
                 style="width:150px" 
                 required="true" 
                 binding="#{country}">
        <f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
        <f:selectItems value="#{dropdownView.countries}" />
        <p:ajax update="city"/>
</p:selectOneMenu>
Noah
  • 68
  • 1
  • 7
  • It works only for Mexico/value 3 to and I choose the Cancun / value 6 option, But if I choose the country Mexico/value 3 and choose the Cancun / value 6 option and few other cities, It fails. Thanks – heidi Mar 04 '20 at 21:48