Default for h:selectOneMenu with jsf

GregD picture GregD · Oct 1, 2013 · Viewed 7.7k times · Source

I'm trying to set a default value for my h:selectOneMenu, but for some reason the first item (see below) is't the first item selected. The 3rd item is the "default selected" item.

<h:selectOneMenu value="#{bookBean.discountPercentage}">
    <f:selectItem itemLabel="Please select a value: " noSelectionOption="true" />
    <f:selectItems value="#{bookBean.paymentMethods}" var="paymentMethod"
                   itemValue="#{paymentMethod.discountPercentage}"
                   itemLabel="#{paymentMethod}" required="true"/>
    <f:ajax listener="#{bookBean.setDiscountValue}"/>
</h:selectOneMenu>

So the "Please select a value" has to be the first item in the list (it is) and it has to be the selected value when opening te page, and it isn't.

Answer

spauny picture spauny · Oct 1, 2013

The first item isn't the selected item in selectOneMenu when the value returned by value="#{bookBean.discountPercentage}" is not null and is equal to an option from the available options.