JSF select menu problem
I am developing a jsf,richfaces application.where i want to populate the values of second select menu on the basis of selecting the choice from the first one .How i can achieve this.
<h:outputText id="section1" value="Section" />
<h:selectOneMenu id="section2" value="#{content.sectionName}" >
<f:selectItems value="#{content.sections}" />
</h:selectOneMenu>
what exactly i want is: I have two tables one for category and one for section. If a user choose a category from drop down menu then the other drop down menu for section should have the values only for selected c开发者_运维技巧ategory.
Please he
As per your question history you're using Ajax4jsf/RichFaces. Better use <a4j:support>
instead of valueChangeListener
.
<h:selectOneMenu id="section2" value="#{content.sectionName}" >
<f:selectItems value="#{content.sections}" />
<a4j:support event="onchange" action="#{content.changeSection}" reRender="otherMenuId" />
</h:selectOneMenu>
In the changeSection()
method you need to populate the select items for the 2nd menu. The otherMenuId
must refer to id
of the other <h:selectOneMenu>
in the same <a4j:region>
.
You have to define a valueChangeListener
for your first selectOneMenu
:
<h:selectOneMenu id="select1" valueChangeListener="#{myBean.updateSections}">
<f:selectItems value="#{myBean.sections1}" />
</h:selectOneMenu>
Inside MyBean#updateSections
you have to modify the list of SelectItems the second selectOneMenu has to show according to the selection you made.
Furthermore you have to submit your form or rerender section2 to display the updated values in section2.
精彩评论