Class SelectItemsIndexConverter

  • All Implemented Interfaces:
    Converter<Object>

    public class SelectItemsIndexConverter
    extends Object
    implements Converter<Object>

    The omnifaces.SelectItemsIndexConverter is a variant of the SelectItemsConverter which automatically converts based on the position (index) of the selected item in the list instead of the Object.toString() of the selected item.

    Usage

    This converter is available by converter ID omnifaces.SelectItemsIndexConverter. Just specify it in the converter attribute of the selection component holding <f:selectItems>.

     <h:selectOneMenu value="#{bean.selectedItem}" converter="omnifaces.SelectItemsIndexConverter">
         <f:selectItems value="#{bean.availableItems}" />
     </h:selectOneMenu>
     

    Since OmniFaces 4.5 it's also available by <o:selectItemsIndexConverter> tag.

     <h:selectOneMenu value="#{bean.selectedItem}">
         <f:selectItems value="#{bean.availableItems}" />
         <o:selectItemsIndexConverter />
     </h:selectOneMenu>
     

    Pros and cons as compared to SelectItemsConverter

    This converter has the following advantages over SelectItemsConverter:

    This converter has the following disadvantage over SelectItemsConverter:

    • The "Validation Error: value is not valid" will never occur anymore for the case that the available select items has incompatibly changed during the postback due to a developer's mistake. The developer should make absolutely sure that exactly the same list is preserved on postback (e.g. by making it a property of a view scoped or broader scoped bean).
    Since:
    1.3
    Author:
    Patrick Dobler, Bauke Scholtz
    See Also:
    SelectItemsUtils, SelectItemsCollector