I got a very funny issues: When I tried to access selectOneMenu selected value by using valueChangeListener's valueChangeEvent. I got itemLabel instead of itemValue.
jsf snappet:
<p:selectOneMenu id="position" value="#{employmentBean.currentEmployment.positionId}" required="true" effect="fold" editable="true"
requiredMessage="Please select an available option." hideNoSelectionOption="true" immediate="true" valueChangeListener="#{employmentControlBean.handlepositionIdSelected}">
<p:ajax update="@form" />
<f:selectItem itemLabel="Select Position to Create Employment." itemValue="" />
<f:selectItems value="#{positionBean.vacantPositionMap.entrySet()}" var="entry" itemLabel="#{entry.value}" itemValue="#{entry.key}"/>
</p:selectOneMenu>
my vacantPositionMap is a
Map<String,String>
style key/value pair, key is position Id, value is position Name.
my backing bean:
@Named(value = "employmentControlBean")
@SessionScoped
public class EmploymentControlBean(){
public void handlepositionIdSelected(ValueChangeEvent event){
........
String positionId = (String) event.getNewValue();
positionBean.setCurrentPosition((Position) positionBean.getPositionCache().get(positionId));
employmentBean.getCurrentEmployment().setPositionId(positionId);
}
}
from above snappet you can see. I am trying to fetch selectOneMenu selected value on valueChangeEvent.
Backing bean method by using ValueChangeEvent, I suppose JSF's itemValue will be passed to backing bean by using ValueChangeEvent.
This is what I found in my html by using firebug:
From above image you can see, primeFaces rendering html correctly, but when I tried to access selected value I get "President". It is not I expected, I expect will get "POSTN20161215xxxxxx".
My question is: Why ValueChangeEvent pass itemLabel instead of itemValue? How I can get the correct value?
Please advise!!