• cdi
  • components
  • contexts
  • converters
  • el
  • eventlisteners
  • exceptionhandlers
  • facesviews
  • filters
  • functions
  • managedbeans
  • push
  • resourcehandlers
  • servlets
  • taghandlers
  • utils
  • validators
  • viewhandlers
  • ImplicitNumberConverter
  • ListConverter
  • ListIndexConverter
  • SelectItemsConverter
  • SelectItemsIndexConverter
  • ToCollectionConverter
  • ToLowerCaseConverter
  • ToUpperCaseConverter
  • TrimConverter
  • ValueChangeConverter

Available since OmniFaces 1.0

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


This converter is available by converter ID omnifaces.ListIndexConverter and should be used in combination with <o:converter> in order to be able to pass the List source to it, which it can use for conversion. Here's a basic usage example with PrimeFaces <p:pickList>, which is one of the few select components which doesn't use SelectItems as the source, but work directly via a List.

<p:pickList value="#{bean.dualListModel}" var="entity" itemValue="#{entity}" itemLabel="#{entity.someProperty}">
    <o:converter converterId="omnifaces.ListIndexConverter" list="#{bean.dualListModel.source}" />

Pros and cons as compared to ListConverter

For detail, refer the javadoc of SelectItemsIndexConverter and substitute "SelectItemsIndexConverter" by "ListIndexConverter" and "SelectItemsConverter" by "ListConverter".


The demo below shows the PrimeFaces <p:pickList> component, which is a famous example of a component that does not use select items.

Choose a city, then press Select:

Selected items: [no selection made]

Another example of such a PrimeFaces component is the <p:autoComplete>.

Selected item: [no selection made]

Demo source code
    The demo below shows the PrimeFaces 
    <a href="http://primefaces.org/showcase/ui/data/pickList.xhtml"><code>&lt;p:pickList&gt;</code></a>
    component, which is a famous example of a component that does not use select items.

        <b>Choose a city, then press Select</b>:
        <p:pickList value="#{selectListBean.model}" var="entity" itemValue="#{entity}" itemLabel="#{entity.value}">
            <o:converter converterId="omnifaces.ListIndexConverter" list="#{selectListBean.fullList}" />

        <h:commandButton value="Select">
            <f:ajax execute="@form" render="@form"/>
        <b>Selected items</b>:
        <ui:repeat value="#{selectListBean.model.target}" var="entity" varStatus="loop">
            #{entity.value}#{loop.last ? '' : ', '}
        <h:outputText value="[no selection made]" rendered="#{empty selectListBean.model.target}"/>

    Another example of such a PrimeFaces component is the
    <a href="http://primefaces.org/showcase/ui/input/autoComplete.xhtml"><code>&lt;p:autoComplete&gt;</code></a>.

    <p:autoComplete value="#{autoCompleteBean.selectedEntity}" completeMethod="#{autoCompleteBean.autoComplete}" 
        var="entity" itemValue="#{entity}" itemLabel="#{entity.value}">
        <o:converter converterId="omnifaces.ListIndexConverter" list="#{autoCompleteBean.availableEntities}" />
        <h:commandButton value="Select">
            <f:ajax execute="@form" render="@form"/>
        <b>Selected item</b>: #{autoCompleteBean.selectedEntity.value}
        <h:outputText value="[no selection made]" rendered="#{empty autoCompleteBean.selectedEntity}"/>
Documentation & Sources