Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top