There is a problem with p:selectOneMenu
selection when adding a f:selectItem
.
View:
<p:selectOneMenu value="#{selectionTest.selectedName}">
<f:selectItem itemLabel="Select" noSelectionOption="true" />
<f:selectItems value="#{selectionTest.allNames}" var="varName" itemLabel="#{varName}" itemValue="#{varName}" />
</p:selectOneMenu>
Model:
private List<String> allNames;
private String selectedName;
public MenuSelectionTestBean(){
allNames = new ArrayList<String>();
allNames.add("Ahmed");
allNames.add("Mohamed");
allNames.add("Ibrahim");
allNames.add("Walid");
selectedName ="Walid";
}
Result:
The item "Walid" should be selected, however "Ibrahim" is selected instead. I think that PrimeFaces selects the item depending on its index in the list and not the value of the item.
How is this caused and how can I solve it?