Time for action – grouping options in SelectOneMenu
Let us see how to display SelectOneMenu options in groups, by performing the following step:
- Create the SelectOneMenu component with option groups using the
SelectItemGroup
andSelectItem
objects:@ManagedBean @RequestScoped public class SelectionController { private List<SelectItem> tagItems = new ArrayList<SelectItem>(); private String selectedTagItem; public SelectionController() { SelectItemGroup g1 = new SelectItemGroup("JavaSE"); g1.setSelectItems(new SelectItem[] {new SelectItem("Threads", "Threads"), new SelectItem("JDBC", "JDBC")}); SelectItemGroup g2 = new SelectItemGroup("JavaEE"); g2.setSelectItems(new SelectItem[] {new SelectItem("JPA", "JPA"), new SelectItem("JMS", "JMS"), new SelectItem("EJB", "EJB")}); tagItems.add(g1...