【问题标题】:SelectOneMenu inside Editable DataTable Shows ItemValue and not itemLable after select可编辑数据表中的 SelectOneMenu 在选择后显示 ItemValue 而不是 itemLable
【发布时间】:2017-03-16 12:32:58
【问题描述】:

我有一个可编辑的数据表,其中一列是 SelectOneMenu,它的 userName 为 itemlable,id 为 itemValue 我的Jsf页面如下

<h:form styleClass="form-horizontal" id="assignIssueId">
            <p:dataTable id="dataTableId" var="issue"
                value="#{assignIssueController.issueList}" editable="true"
                editMode="cell" widgetVar="cellCars">
                <f:facet name="header">
                     Cell Editing with Click and RightClick
                 </f:facet>
                <p:ajax event="cellEdit"
                    listener="#{assignIssueController.onCellEdit}" />
                <p:column headerText="Issue Number">
                    <h:outputText value="#{issue[0]}" />
                </p:column>
                <p:column headerText="Issue Describtion">
                    <h:outputText value="#{issue[1]}" />
                </p:column>
                <p:column headerText="Issue Type">
                    <h:outputText value="#{issue[2]}" />
                </p:column>
                <p:column headerText="Assign To">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{issue[3]}" />
                        </f:facet>
                        <f:facet name="input">
                            <h:selectOneMenu value="#{assignIssueController.userId}"
                                style="width:100%">
                                <f:selectItems value="#{assignIssueController.userlist}"
                                    var="ul" itemLabel="#{ul.firstName}" itemValue="#{ul.id}" />
                            </h:selectOneMenu>
                        </f:facet>
                    </p:cellEditor>
                </p:column>
                <p:column headerText="Issue Type">
                    <h:outputText value="#{issue[4]}" />
                </p:column>
            </p:dataTable>
        </h:form>

这里的问题是我可以编辑 selectOneMenu,但是从下拉菜单中选择值后,它会显示新选定用户的 ID,而不是 dataTable 中的名称

【问题讨论】:

  • 你想用 issue[3] 显示什么?
  • 它的列表 其中一个可以根据要分配的问题选择用户
  • 你应该将 ul 设置为 itemValue,然后当你选择一个用户时你会触发一个事件,在该事件中你将所选用户设置为 issue[3]

标签: jsf primefaces jsf-2


【解决方案1】:

看起来像一个转换错误.. 用户对象的 'id' 属性是否可能与您将所选值分配给的 'userID' 类型不同,或者 'id' 不是原始类型或字符串,因此您需要自定义转换器?

【讨论】:

  • 两者都是 int 类型。
  • 好的,奇怪...但是由于您已经在项目中使用 primefaces,您可以尝试使用 ...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-29
  • 1970-01-01
  • 2012-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多