我有两个级联p:selectOneMenu
组件。第一个显示来自 hashmap 的区域,第二个显示通过 ajax 选择区域的城市。但是当提交选择城市的表格时,我得到
验证错误:值无效
这是视图
<p:selectOneMenu id="area" value="#{bean.area}">
<f:selectItem itemLabel="Select Area" itemValue="" />
<f:selectItems value="#{bean.areas}" />
<p:ajax update="city" listener="#{bean.handleAreaChange()}" />
</p:selectOneMenu>
<p:selectOneMenu id="city" value="#{bean.city}">
<f:selectItem itemLabel="Select City" itemValue="" />
<f:selectItems value="#{bean.cities}" />
</p:selectOneMenu>
这是豆子:
private String area;
private String city;
private Map<String, String> areas = new HashMap<String, String>();
private Map<String, String> cities = new HashMap<String, String>();
private Map<String, Map<String, String>> allCities = new HashMap<String, Map<String,String>>();
public void handleAreaChange() {
if (area != null && !area.isEmpty()) {
cities = allCities.get(area);
} else {
cities = new HashMap<String, String>();
}
}
这是如何引起的,我该如何解决?