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:
- 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>
- 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 Tag(1, "JavaSE", "java-se", "Java...