I have a <p:dataTable>
with lazy load. In two of the columns, there is a <p:selectOneMenu>
in each of them.
The first column holds a list of countries and the second one holds a list of states from a database.
I want the second menu (the one that contains a list of states) to show only those states in each row of the data table which correspond to the country in the first menu in each row of the data table.
During edit mode, when a country in its menu is changed, the states corresponding to that country should be populated in its menu in that current row.
How to load such lists of states that correspond to their countries in each row of the data table?
These two columns in the data table are left incomplete, since I don't have a precise idea about how to achieve this.
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.state.country.countryName}"/>
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{row.state.country}">
<f:selectItems var="country"
value="#{cityBean.selectedCountries}"
itemLabel="#{country.countryName}"
itemValue="#{country}"/>
<p:ajax update="states" listener="#{cityBean.getStates}"/>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.state.stateName}"/>
</f:facet>
<f:facet name="input">
<p:selectOneMenu id="states">
<f:selectItems var="state"
value="#{cityBean.selectedStates}"
itemLabel="#{state.stateName}"
itemValue="#{state}"/>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
cityBean.selectedCountries
retrieves all the countries which is necessary but cityBean.selectedStates
also retrieves all the states from the database which is unnecessary and should be modified to retrieve only those states which correspond to its country in another menu.
How can I proceed from here?