【问题标题】:Display Item Label for drop down list, radio button, many check box and boolean check box instead of item value显示下拉列表、单选按钮、许多复选框和布尔复选框的项目标签,而不是项目值
【发布时间】:2016-12-21 14:15:39
【问题描述】:

我正在开发一个包含各种元素的客户资料页面,即。 h:selectOneMenuh:selectOneRadioh:selectBooleanCheckboxh: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


【解决方案1】:

jsf 控件替换为primefaces 控件,即。 p:selectOneMenup:selectManyCheckbox 解决了显示值而不是代码的问题。

【讨论】:

    猜你喜欢
    • 2016-05-10
    • 2016-02-07
    • 2015-02-05
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 2016-04-03
    • 1970-01-01
    相关资源
    最近更新 更多