- java.lang.Object
-
- org.omnifaces.converter.ToCollectionConverter
-
- All Implemented Interfaces:
Converter<Collection>
public class ToCollectionConverter extends Object implements Converter<Collection>
The
omnifaces.ToCollectionConverteris intented to convert submittedStringvalues 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 theconverterattribute of the component referring theCollectionproperty. 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.LinkedHashSetfor aSetproperty andjava.util.ArrayListfor 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. Thedelimitermust be aString, thecollectionTypemust be a FQN and theitemConvertercan 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 CollectiongetAsObject(FacesContext context, UIComponent component, String submittedValue)StringgetAsString(FacesContext context, UIComponent component, Collection modelValue)voidsetCollectionType(String collectionType)Sets the FQN of the collection to create.voidsetDelimiter(String delimiter)Sets the delimiter to split on.voidsetItemConverter(Object itemConverter)Sets the converter for the item.
-
-
-
Method Detail
-
getAsObject
public Collection getAsObject(FacesContext context, UIComponent component, String submittedValue)
- Specified by:
getAsObjectin interfaceConverter<Collection>
-
getAsString
public String getAsString(FacesContext context, UIComponent component, Collection modelValue)
- Specified by:
getAsStringin 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.
-
-