【发布时间】:2011-07-25 15:33:33
【问题描述】:
I am trying to display a page where the user, by the appropriate selection using a radio button, sees either a textbox or a combo box.这相对容易,我通过以下代码设法做到了:
<h:selectOneRadio id="selection" value="#{inputMethod.choice}">
<f:selectItem itemValue="#{inputMethod.TEXT}" itemLabel="textbox"/>
<f:selectItem itemValue="#{inputMethod.COMBO}" itemLabel="combobox" />
<f:ajax event="click" execute="@this" render="@form" />
</h:selectOneRadio>
<h:panelGroup id="Textbox" rendered="#{inputMethod.choice==inputMethod.TEXT}">
<h:outputLabel>Textbox:</h:outputLabel>
<h:inputText value="#{myBean.somevalue}" />
</h:panelGroup>
<h:panelGroup id="Combobox" rendered="#{inputMethod.choice==inputMethod.COMBO}">
<h:outputLabel Combobox:/>
<h:selectManyListbox id="CommunityListbox" value="#{myBean.choices}">
<f:selectItems value="#{myBean.selections}" var="u" itemValue="#{u.id}" itemLabel="#{u.name}"/>
</h:selectManyListbox>
</h:panelGroup>
我遇到的问题是组合框的设置器从未被调用。
事实上,setter 只为默认渲染的组件调用(在这种情况下,只要inputMethod.choice==inputMethod.TEXT)。如果我删除条件渲染,所有设置器都会按预期调用。
任何想法或答案将不胜感激!
PS:我正在使用 jsf2.0、Glassfish 3.1、Netbeans 7.0(以防万一这很重要)
【问题讨论】: