【发布时间】:2016-12-21 14:15:39
【问题描述】:
我正在开发一个包含各种元素的客户资料页面,即。 h:selectOneMenu、h:selectOneRadio、h:selectBooleanCheckbox、h:selectManyCheckbox 使用来自数据库的主值使用 List<MasterDTO> 填充。当页面处于编辑模式时,元素会完美显示。但是,当页面更改为查看模式时,将显示所选项目的值,而不是显示所选项目的标签。例如。需要在查看模式下将Single 显示为Marital Status,而不是显示001。
请参考下面的示例代码。我不想在所有代码中将List 对象更改为Map<K,V>。我正在使用 JSF 2.0 和 Primefaces 3.4.2。有解决办法吗?
选择一个菜单
<h:selectOneMenu id="marital_status" style="width:178px;"
rendered="#{customerProfileBean.editMode}"
value="#{customerProfileBean.marital_status}">
<f:selectItem itemValue="-1" itemLabel="--- Select ---" />
<f:selectItems value="#{customerProfileBean.maritalStatusList}"
var="mst" itemLabel="#{mst.valueName}" itemValue="#{mst.valueCode}" />
</h:selectOneMenu>
<h:outputText rendered="#{not customerProfileBean.editMode}"
value="#{customerProfileBean.marital_status}" />
选择多个复选框
<h:selectManyCheckbox id="loanTypes" styleClass="selectOptionSpace"
rendered="#{customerProfileBean.editMode}"
value="#{customerProfileBean.loanTypes}">
<f:selectItems value="#{customerProfileBean.creditFacList}"
var="mst" itemLabel="#{mst.valueName}" itemValue="#{mst.valueCode}" />
</h:selectManyCheckbox>
<h:outputText rendered="#{not customerProfileBean.editMode}"
value="#{customerProfileBean.custLoanType}" />
【问题讨论】:
-
这与 primefaces 无关。您只需在示例中使用 jsf。 Primefaces 将是 p:selectOneMenu 和 p:selectManyCheckbox。顺便说一句,您的 primefaces 版本已经完全过时了。最新的社区版本是 6.0。
-
您似乎在 maritalStatusList 中项目的 valueName 属性中有“标签”。因此,基于 marital_status 值显示这一点的简单 java 端方法将解决您的问题......实际上甚至没有 jsf 相关...
标签: jsf-2