Jsf 2 在ui内显示多个p:selectOneMenu:根据上一个菜单的选定值重复
我想根据上一个Jsf 2 在ui内显示多个p:selectOneMenu:根据上一个菜单的选定值重复,jsf-2,primefaces,selectonemenu,country,uirepeat,Jsf 2,Primefaces,Selectonemenu,Country,Uirepeat,我想根据上一个的选定值在中显示多个组件,直到到达树的叶子 例如,中的第一个国家列表。现在我选择一个国家,比如巴基斯坦。现在,在内部将有第二个组件与巴基斯坦的城市。现在,我选择一个城市,然后应该有第三个和城市的扇区,依此类推,直到从数据库中找不到任何记录 我怎样才能做到这一点?这个是不适合的。首先,数据库中没有无限多的表。只需根据DB表中可用的select项有条件地呈现子体下拉列表 <p:selectOneMenu value="#{bean.country}">
的选定值在
中显示多个
组件,直到到达树的叶子
例如,
中的第一个国家列表。现在我选择一个国家,比如巴基斯坦。现在,在
内部将有第二个
组件与巴基斯坦的城市。现在,我选择一个城市,然后应该有第三个
和城市的扇区,依此类推,直到从数据库中找不到任何记录
我怎样才能做到这一点?这个
是不适合的。首先,数据库中没有无限多的表。只需根据DB表中可用的select项有条件地呈现子体下拉列表
<p:selectOneMenu value="#{bean.country}">
<f:selectItem itemValue="#{null}" itemLabel="--select country--" />
<f:selectItems value="#{bean.countries}" />
<p:ajax listener="#{bean.changeCountry}" update="cities" />
</p:selectOneMenu>
<h:panelGroup id="cities">
<p:selectOneMenu value="#{bean.city}" rendered="#{not empty bean.cities}">
<f:selectItem itemValue="#{null}" itemLabel="--select city--" />
<f:selectItems value="#{bean.cities}" />
<p:ajax listener="#{bean.changeCity}" update="sectors" />
</p:selectOneMenu>
</h:panelGroup>
<h:panelGroup id="sectors">
<p:selectOneMenu value="#{bean.sector}" rendered="#{not empty bean.sectors}">
<f:selectItem itemValue="#{null}" itemLabel="--select sector--" />
<f:selectItems value="#{bean.sectors}" />
</p:selectOneMenu>
</h:panelGroup>
当然,您可以使用国家
、城市
和行业
实体以及(通用)转换器来代替字符串
另见:
private List<String> countries;
private String country;
private List<String> cities;
private String city;
private List<String> sectors;
private String sector;
@EJB
private LocationService locationService;
@PostConstruct
public void init() {
countries = locationService.getCountries();
}
public void changeCountry() {
cities = locationService.getCities(country);
city = null;
sectors = null;
}
public void changeCity() {
sectors = locationService.getSectors(city);
sector = null;
}