- java.lang.Object
-
- org.omnifaces.converter.ListIndexConverter
-
public class ListIndexConverter extends Object implements Converter<Object>
The
omnifaces.ListIndexConverter
is a variant of theListConverter
which automatically converts based on the position (index) of the selected item in the list instead of theObject.toString()
of the selected item.Usage
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 theList
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 useSelectItem
s as the source, but work directly via aList
.<p:pickList value="#{bean.dualListModel}" var="entity" itemValue="#{entity}" itemLabel="#{entity.someProperty}"> <o:converter converterId="omnifaces.ListIndexConverter" list="#{bean.dualListModel.source}" /> </p:pickList>
Since OmniFaces 4.5 it's also available by
<o:listIndexConverter>
tag.<p:pickList value="#{bean.dualListModel}" var="entity" itemValue="#{entity}" itemLabel="#{entity.someProperty}"> <o:listIndexConverter" list="#{bean.dualListModel.source}" /> </p:pickList>
Pros and cons as compared to
ListConverter
For detail, refer the javadoc of
SelectItemsIndexConverter
and substitute "SelectItemsIndexConverter
" by "ListIndexConverter
" and "SelectItemsConverter
" by "ListConverter
".- Author:
- Arjan Tijms
-
-
Field Summary
-
Fields inherited from interface jakarta.faces.convert.Converter
DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME
-
-
Constructor Summary
Constructors Constructor Description ListIndexConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
getAsObject(FacesContext context, UIComponent component, String value)
String
getAsString(FacesContext context, UIComponent component, Object value)
void
setList(List<?> list)
Sets the list of available items.
-
-
-
Method Detail
-
getAsObject
public Object getAsObject(FacesContext context, UIComponent component, String value)
- Specified by:
getAsObject
in interfaceConverter<Object>
-
getAsString
public String getAsString(FacesContext context, UIComponent component, Object value)
- Specified by:
getAsString
in interfaceConverter<Object>
-
setList
public void setList(List<?> list)
Sets the list of available items.- Parameters:
list
- The list of available items.
-
-