Choosing a single item with selectOneMenu
The selectOneMenu
component is an extended version of JSF selectOneMenu
. It provides custom content display along with skinning capabilities.
How to do it…
The simplest component declaration would be as follows:
<p:selectOneMenu> <f:selectItem itemLabel="English" itemValue="en"/> <f:selectItem itemLabel="Turkish" itemValue="tr"/> </p:selectOneMenu>
The output visual will be as follows:
There's more...
Instead of working with primitive types or just string literals, most of the time we would be using the selectOneMenu
component with domain objects. The basic definition of the component for listing the cars for a given brand would be as follows:
<p:selectOneMenu id="carPOJO" value="#{selectOneMenuBean.selectedCar}" var="car"> <f:converter converterId="org.primefaces.cookbook.converter.CarConverter" /> <f:selectItems value="#{selectOneMenuBean.cars}" var="c" itemLabel="#{c.name}" itemValue="#{c}" />...