我有一个复选框,可以呈现2个下拉菜单SelectOne菜单,第一个SelectOne菜单中的项目是静态的,但第二个SelectOne菜单应该根据第一个选项更新项目。我如何在primefaces中这样做?
例如国家和城镇,当我在第一个菜单中选择英国时,我想在第二个城镇看到仅来自英国的城镇。
<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>
我的豆子
private boolean checkBoxSelected=false;
public void CheckBoxEvent(ValueChangeEvent vcEvent){
checkBoxSelected = Boolean.valueOf(vcEvent.getNewValue().toString()).booleanValue();
}
答案 0 :(得分:0)
尝试primefaces ajax事件:
<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>
我的豆子
private List<String> regions;
private int number;
public void handleDropDownChange(){
//based on the number provided, change "regions" attribute.
}