I have a checkBox that renders 2 drop-down SelectOne Menus, the items in the first SelectOne Menu is static, but the second SelectOne Menu should update items based on selection from the first. How do I do this in primefaces?
For example country and towns, when i select the UK in first menu, I want to see in the second, towns only from UK.
<h:selectBooleanCheckbox id="checkboxId" value="#{myBean.checkBoxSelected}" >
<p:ajax event="CheckBoxEvent" update="panelId" />
</h:selectBooleanCheckbox>
<h:panelGrid id="panelId" style="border:solid 1px black;" >
<h:outputText value="(country) First drop-down: " />
<p:selectOneMenu value="#{myBean.number}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItem itemLabel="UK" itemValue="1" />
<f:selectItem itemLabel="SUA" itemValue="2" />
<f:selectItem itemLabel="Italy" itemValue="3" />
</p:selectOneMenu>
<h:outputText value="(region) Second drop-down: " />
<p:selectOneMenu value="#{myBean.number}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItem itemLabel="country region 1" itemValue="1" />
<f:selectItem itemLabel="country region 2" itemValue="2" />
<f:selectItem itemLabel="country region 3" itemValue="3" />
</p:selectOneMenu>
</h:panelGrid>
My Bean
private boolean checkBoxSelected=false;
public void CheckBoxEvent(ValueChangeEvent vcEvent){
checkBoxSelected = Boolean.valueOf(vcEvent.getNewValue().toString()).booleanValue();
}
try primeface's ajax event:
<h:outputText value="(country) First drop-down: " />
<p:selectOneMenu value="#{myBean.number}">
<f:selectItem itemLabel="UK" itemValue="1" />
<f:selectItem itemLabel="SUA" itemValue="2" />
<f:selectItem itemLabel="Italy" itemValue="3" />
<p:ajax update="dropdown2" listener="#{myBean.handleDropDownChange}" />
</p:selectOneMenu>
<h:outputText value="(region) Second drop-down: " />
<p:selectOneMenu value="#{myBean.number}" id="dropdown2">
<f:selectItems value="#{myBean.regions}" />
</p:selectOneMenu>
My Bean
private List<String> regions;
private int number;
public void handleDropDownChange(){
//based on the number provided, change "regions" attribute.
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.