cidy.long
cidy.long

Reputation: 427

Primefaces 6.1 SelectOneMenu pick itemLabel as value

I am using PrimeFaces 6.1 SelectOneMenu to render a editable/filtered dropdown menu with itemLabel/value as selectItems. Unfortunately, selectOneMenu pick itemLabel as value put it in my selectOneMenu value field. This is very annoying issue and maybe it is a bug.

There is my snippet code:

I am using Map to hold ID/Name pair as selectItems:

Map<String,String> hm = new HashMap<String, String>();
hm.put("Cust001","John Dow");
hm.put("Cust002","Mark Polo");
hm.put("Cust003","Noel Max");

then I put it in my selectOneMenu as:

<p:selectOneMenu id="selectCustomerId" value="#{paymentControlBean.selectedCustomerId}" effect="fold" editable="true" filter="true" filterMatchMode="startsWith">
   <p:ajax update="paymentListToolbar"/>
   <f:selectItems value="#{hm.entrySet()}" var="entry" itemValue="#{entry.key}" itemLabel="#{entry.value}"/>
</p:selectOneMenu>

Dropdown list rendering works fine, but when I pick one from the dropdown list and then press process it. My backing bean paymentControlBean.selectedCustomerId shows up "John Dow", which means, selectOneMenu pick my itemLabel into my selectOneMenu's value field.

I tried to change the PrimeFaces element to p:selectOneListBox and keep everything no change, repeat the processing, my backing bean shows up "Cust001", which is working fine.

From this comparison I found out, there must a serious bug exists in PrimeFaces 6.1, and it is same bug existing in PrimeFaces 5.2 as well.

SelectOneMenu is very popular in dropdown list selection, especially when we have to handle key/value pairs by using Map.

If it is not a bug, what I can do or have an other work around to make it pick up right value in my selectItems?

Please advise>

Upvotes: 1

Views: 1256

Answers (1)

Melloware
Melloware

Reputation: 12019

I have fixed it with this PR: https://github.com/primefaces/primefaces/pull/2870

It will be in PrimeFaces 6.2 release coming out in November 2017.

Upvotes: 1

Related Questions