我需要根据另一个下拉列表中的选定值填充下拉列表。我可以使用AJAX请求来做到这一点,但我只是在寻找使用JSF的解决方案。每次用户更改其选择时,填充下拉列表的值都需要来自表格。
由于
答案 0 :(得分:2)
你没有指定版本,所以我假设JSF 1.2。 <a4j:support>
代码是RichFaces的一部分:
<h:selectOneMenu id="firstDropDown" value="#{bean.firstDropDownSelection}">
<f:selectItems value="#{bean.items}" />
<a4j:support event="onchange" reRender="secondDropDown"
immediate="true" action="#{bean.fetchItems2}" />
</h:selectOneMenu>
<h:selectOneMenu id="secondDropDown" value="#{bean.secondDropDownSelection}">
<f:selectItems value="#{bean.items2}" />
</h:selectOneMenu>
在方法bean.fetchItems2
中,您可以使用相应的项目加载集合items2
。
会发生什么,当第一个下拉列表的值发生变化时,第二个下拉列表会被重新呈现,并且它的值会再次从服务器中获取。