1

I have a p:selectOneMenu which is filled by SelectItem from the backing bean. Say the list has 4 items: Mango, Apple, Banana, Grapes. Here I want to show Banana as the default value selected on the page loads. How do I achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Preeti Singh
  • 37
  • 3
  • 12

1 Answers1

0

Consider this example:

                         <h:selectOneMenu 
                                valueChangeListener="#{cust.setRetailerId}"
                                onchange="submit()">
                                <f:selectItem itemValue="#{null}" 
                                itemLabel="-- select retailer --" noSelectionOption="true" />

                                <f:selectItems value="#{cust.getRetailers()}" var="retailer" 
                                itemValue="#{retailer.id}" itemLabel="#{retailer.name}" />

                            </h:selectOneMenu>

In this first option will be the default output with the tag noseletoption = "true".

Haseeb Anser
  • 494
  • 1
  • 5
  • 19