O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using SelectOneMenu with POJOs

In this section, we will demonstrate how to use SelectOneMenu backed by a collection of POJOs by using a converter, by performing the following steps:

  1. Create a SelectOneMenu component using List<Tag> POJOs:
    <p:selectOneMenu value="#{selectionController.selectedTag}" converter="tagConverter">  
        <f:selectItem itemLabel="Select One" itemValue="" />  
        <f:selectItems value="#{selectionController.tagPojos}" var="tag" itemLabel="#{tag.label}" itemValue="#{tag}"/>  
    </p:selectOneMenu>
  2. Initialize List<Tag> POJOs in the managed bean:
    @ManagedBean @RequestScoped public class SelectionController { private List<Tag> tagPojos; private Tag selectedTag; public SelectionController() { tagPojos = new ArrayList<Tag>(); tagPojos.add(new ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required