问题
I'm using Primefaces 3.5 5th December 2012 SNAPSHOT, with Mojarra 2.1.14 and Tomcat 7.0.33.
When using the in-cell editing mode (not in-row) for POJO objects with a model/entity class that are represented in a h:selectOneMenu, with 'click' as the celleditevent value, whenever you click on an object and then 'click away' by clicking on some other object, the previous object is displaying its value instead of its label. This is only 'cosmetic' as when you reload the page, it will show the label value.
<p:dataTable id="insurancepolicyTable" var="insurancepolicy" widgetVar="insurancepolicyList" value="#{insurancepolicybean.objectList}" paginator="true" rows="15" paginatorPosition="bottom" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" currentPageReportTemplate="#{text['table.insurancepolicy.filter.count']}" rowsPerPageTemplate="15,25,50,100" emptyMessage="#{text['table.insurancepolicy.filter.notfound']}" filteredValue="#{insurancepolicybean.filteredObject}" editable="true" editMode="cell" cellEditEvent="click" draggableColumns="true" rowKey="#{insurancepolicy.id}" >
<p:column id="branchColumn" headerText="#{text['label.branch']}" sortBy="#{insurancepolicy.branch.name}" filterBy="#{insurancepolicy.branch.name}" filterMatchMode="contains">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{insurancepolicy.branch.name}" />
</f:facet>
<f:facet name="input">
<div class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all">
<p:selectOneMenu id="branchselectinsurancepolicylist" value="#{insurancepolicy.branch}" styleClass="customSelect" converter="omnifaces.SelectItemsIndexConverter">
<f:selectItems value="#{insurancepolicybean.branchList}" var="branch" itemLabel="#{branch.name}" itemValue="#{branch}" />
</p:selectOneMenu>
</div>
</f:facet>
</p:cellEditor>
</p:column>
<p:ajax event="cellEdit" listener="#{insurancepolicybean.onEdit}" update="@form" />
<pe:resetInput event="cellEdit" for="@form" />
</p:dataTable>
回答1:
I can reproduce it. It's a bug in PrimeFaces. This problem is not related to the converter. The problem is just caused by PrimeFaces-specific JavaScript code which incorrectly redisplays the value of the selected option instead of the label of the selected option after "unedit".
This is more easily to be reproduced as follows:
<p:selectOneMenu value="#{insurancepolicy.branchAsString}">
<f:selectItems value="#{insurancepolicybean.branchMap}" />
</p:selectOneMenu>
with
private Map<String, String> branchMap;
@PostConstruct
public void init() {
branchMap = new LinkedHashMap<String, String>();
branchMap.put("branch label 1", "branch value 1");
branchMap.put("branch label 2", "branch value 2");
branchMap.put("branch label 3", "branch value 3");
}
I recommend to report it to PrimeFaces guys.
来源:https://stackoverflow.com/questions/13722661/primefaces-3-5-omnifaces-1-3-selectitemsindexconverter-issue-with-selectonemen