- java.lang.Object
-
- org.omnifaces.converter.ToCollectionConverter
-
- All Implemented Interfaces:
Converter<Collection>
public class ToCollectionConverter extends Object implements Converter<Collection>
The
omnifaces.ToCollectionConverter
is intented to convert submittedString
values to a Java collection based on a delimiter. Additionally, it trims any whitespace around each delimited submitted value. This is useful for among others comma separated value inputs.Usage
This converter is available by converter ID
omnifaces.ToCollectionConverter
. Just specify it in theconverter
attribute of the component referring theCollection
property. For example:<h:inputText value="#{bean.commaSeparatedValues}" converter="omnifaces.ToCollectionConverter" />
The default delimiter is comma followed by space
,
and the default collection type isjava.util.LinkedHashSet
for aSet
property andjava.util.ArrayList
for anything else, and the default converter for each item will ingetAsString()
be determined based on item type and ingetAsObject()
be determined based on generic return type of the getter method.You can use
<o:converter>
to specify those attributes. Thedelimiter
must be aString
, thecollectionType
must be a FQN and theitemConverter
can be anything which is acceptable byFaces.createConverter(Object)
.<h:inputText value="#{bean.uniqueOrderedSemiColonSeparatedNumbers}"> <o:converter converterId="omnifaces.ToCollectionConverter" delimiter=";" collectionType="java.util.TreeSet" itemConverter="jakarta.faces.Integer" > </h:inputText>
- Since:
- 2.6
- Author:
- Bauke Scholtz
- See Also:
TrimConverter
-
-
Field Summary
-
Fields inherited from interface jakarta.faces.convert.Converter
DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME
-
-
Constructor Summary
Constructors Constructor Description ToCollectionConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection
getAsObject(FacesContext context, UIComponent component, String submittedValue)
String
getAsString(FacesContext context, UIComponent component, Collection modelValue)
void
setCollectionType(String collectionType)
Sets the FQN of the collection to create.void
setDelimiter(String delimiter)
Sets the delimiter to split on.void
setItemConverter(Object itemConverter)
Sets the converter for the item.
-
-
-
Method Detail
-
getAsObject
public Collection getAsObject(FacesContext context, UIComponent component, String submittedValue)
- Specified by:
getAsObject
in interfaceConverter<Collection>
-
getAsString
public String getAsString(FacesContext context, UIComponent component, Collection modelValue)
- Specified by:
getAsString
in interfaceConverter<Collection>
-
setDelimiter
public void setDelimiter(String delimiter)
Sets the delimiter to split on.- Parameters:
delimiter
- The delimiter to split on.
-
setCollectionType
public void setCollectionType(String collectionType)
Sets the FQN of the collection to create.- Parameters:
collectionType
- The FQN of the collection to create.
-
setItemConverter
public void setItemConverter(Object itemConverter)
Sets the converter for the item.- Parameters:
itemConverter
- The converter for the item.
-
-