开发者

JSF - Populating a drop down depending on value in other drop down

I need to populate a drop down based on the selected value in another drop down. I can use AJAX requests to do that but I am searching for a solution using JSF only. The values to populate the drop down need to come from a table every time user ch开发者_Go百科anges his selection.

Thanks


You didn't specify the version, so I'll assume JSF 1.2. The <a4j:support> tag is part of 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>

And in the method bean.fetchItems2 you load your collection items2 with the appropriate items.

What happens, is when the value of the first drop down changes, the second drop down is rerendered and its value is fetched from the server again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜