Class SelectItemGroups

All Implemented Interfaces:
PartialStateHolder, StateHolder, TransientStateHolder, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder, EventListener

public class SelectItemGroups extends UISelectItems

The o:selectItemGroups is an extension of UISelectItems which allows you to iterate over a nested collection representing groups of select items. This is basically the UIComponent counterpart of jakarta.faces.model.SelectItemGroup. There is no equivalent (yet) in the standard Faces API. Currently the only way to represent SelectItemGroup in UI is to manually create and populate them in a backing bean which can end up to be quite verbose.

Usage

Below example assumes a List<Category> as value wherein Category in turn has a List<Product>.

 <h:selectOneMenu value="#{bean.selectedProduct}" converter="omnifaces.SelectItemsConverter">
     <f:selectItem itemValue="#{null}" />
     <o:selectItemGroups value="#{bean.categories}" var="category" itemLabel="#{category.name}">
         <f:selectItems value="#{category.products}" var="product" itemLabel="#{product.name}" />
     </o:selectItemGroups>
 </h:selectOneMenu>
 
Since:
3.0
Author:
Bauke Scholtz
  • Field Details

    • COMPONENT_TYPE

      public static final String COMPONENT_TYPE
      The component type, which is "org.omnifaces.component.model.SelectItemGroups".
      See Also:
  • Constructor Details

    • SelectItemGroups

      public SelectItemGroups()
  • Method Details

    • setValueExpression

      public void setValueExpression(String name, ValueExpression binding)
      An override which checks if this isn't been invoked on var attribute. Finally it delegates to the super method.
      Overrides:
      setValueExpression in class UIComponent
      Throws:
      IllegalArgumentException - When this value expression is been set on var attribute.
    • getValue

      public Object getValue()
      An override which wraps each UISelectItem(s) child in a SelectItemGroup.
      Overrides:
      getValue in class UISelectItems
    • getVar

      public String getVar()
      Returns the name of the EL variable which exposes the currently iterated select item group. Defaults to item.
      Returns:
      The name of the EL variable.
    • setVar

      public void setVar(String varName)
      Sets the name of the EL variable which exposes the currently iterated select item group. Defaults to item.
      Parameters:
      varName - The name of the EL variable.
    • getItemLabel

      public String getItemLabel()
      Returns the label of the select item group. Defaults to the String representation of itemValue.
      Returns:
      The label of the select item group.
    • setItemLabel

      public void setItemLabel(String itemLabel)
      Sets the label of the select item group. Defaults to the String representation of itemValue.
      Parameters:
      itemLabel - The label of the select item group.
    • getItemValue

      public Object getItemValue()
      Returns the value of the select item group. This will be exposed to any nested UISelectItem(s) children. Defaults to the currently iterated select item group.
      Returns:
      The value of the select item group.
    • setItemValue

      public void setItemValue(Object itemValue)
      Sets the value of the select item group. This will be exposed to any nested UISelectItem(s) children. Defaults to the currently iterated select item group.
      Parameters:
      itemValue - The value of the select item group.
    • setValue

      public void setValue(Object value)
      Overrides:
      setValue in class UISelectItems