Class ListConverter
- java.lang.Object
-
- org.omnifaces.converter.ListConverter
-
public class ListConverter extends Object implements Converter<Object>
The
omnifaces.ListConverteris intented for use in specialized selection components which doesn't useSelectItems as the source for their selectable items, but work directly via aListof entities, and therefore theSelectItemsConverterisn't usable on them.This converter allows you to populate a selection component with complex Java objects and have Faces convert those automatically back without the need to provide a custom converter which may need to do the job based on possibly expensive service/DAO operations. This converter automatically converts based on the
Object.toString()of the selected item.Usage
This converter is available by converter ID
omnifaces.ListConverterand should be used in combination with<o:converter>in order to be able to pass theListsource 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 useSelectItems as the source, but work directly via aList.<p:pickList value="#{bean.dualListModel}" var="entity" itemValue="#{entity}" itemLabel="#{entity.someProperty}"> <o:converter converterId="omnifaces.ListConverter" list="#{bean.dualListModel.source}" /> </p:pickList>Make sure that your entity has a good
toString()implementationFor detail, refer the javadoc of
SelectItemsConverterand substitute "SelectItemsConverter" by "ListConverter" and "SelectItemsIndexConverter" by "ListIndexConverter".- Since:
- 1.5
- 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 ListConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectgetAsObject(FacesContext context, UIComponent component, String value)StringgetAsString(FacesContext context, UIComponent component, Object value)voidsetList(List<?> list)Sets the list of available items.
-
-
-
Method Detail
-
getAsObject
public Object getAsObject(FacesContext context, UIComponent component, String value)
- Specified by:
getAsObjectin interfaceConverter<Object>
-
getAsString
public String getAsString(FacesContext context, UIComponent component, Object value)
- Specified by:
getAsStringin interfaceConverter<Object>
-
setList
public void setList(List<?> list)
Sets the list of available items.- Parameters:
list- The list of available items.
-
-