【发布时间】:2012-02-08 19:57:09
【问题描述】:
我在 Tomcat 7 上运行的 JSF-2 Mojarra 2.0.8 中有以下代码
<h:panelGrid id="yesNoRadioGrid">
<h:panelGrid columns="2" rendered="#{user.yesNoRadioGridFlag}">
<h:outputText id ="otherLbl" value="Select Yes or No"></h:outputText>
<h:selectOneRadio id="yesNoRadio" value ="#{user.yesNoRadio}">
<f:selectItems value="#{user.choices}"/>
<f:ajax execute="@form" render="userDetailsGrid "></f:ajax>
</h:selectOneRadio>
</h:panelGrid>
</h:panelGrid>
<h:message for ="yesNoRadio"> </h:message>
<h:panelGrid id="userDetailsGrid">
<h:panelGrid columns="2" rendered="#{user.yesNoRadio}">
<h:outputLabel>Name :</h:outputLabel>
<h:inputText id="customerName" value="#{user.customerName}"></h:inputText>
<h:outputLabel>Salary: </h:outputLabel>
<h:inputText id="customerSalary" value="#{user.customerSalary}"></h:inputText>
</h:panelGrid>
</h:panelGrid>
我的 managedBean 包含以下内容
private enum Choice {
Yes, No;
}
private Choice yesNoRadio;
public Choice[] getChoices() {
return Choice.values();
}
public Choice getYesNoRadio() {
return yesNoRadio;
}
public void setYesNoRadio(Choice yesNoRadio) {
this.yesNoRadio = yesNoRadio;
}
如何根据在
中选择的布尔值 (user.yesNoRadio) 呈现我的“userDetailsGrid”我通过在我的 mangedbean 中添加以下内容找到了解决方法
private Boolean yesNoRadio;
public SelectItem[] getMyBooleanValues() {
return new SelectItem[] {
new SelectItem(Boolean.TRUE, "Yes"),
new SelectItem(Boolean.FALSE, "No")
};
}
并将我的观点改为
<h:selectOneRadio id="yesNoRadio" value ="#{user.yesNoRadio}">
<f:selectItems value="#{user.myBooleanValues}" />
<f:ajax execute="@form" render="userDetailsGrid "></f:ajax>
</h:selectOneRadio>
【问题讨论】:
标签: jsf-2