- All Implemented Interfaces:
Converter<Collection>
The omnifaces.ToCollectionConverter is intented to convert submitted String 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 the
converter attribute of the component referring the Collection property. For example:
<h:inputText value="#{bean.commaSeparatedValues}" converter="omnifaces.ToCollectionConverter" />
Since OmniFaces 4.5 it's also available by <o:toCollectionConverter> tag.
<h:inputText value="#{bean.commaSeparatedValues}">
<o:toCollectionConverter />
</h:inputText>
The default delimiter is comma followed by space , and the default collection type is
java.util.LinkedHashSet for a Set property and java.util.ArrayList for anything
else, and the default converter for each item will in getAsString() be determined based on item type and
in getAsObject() be determined based on generic return type of the getter method.
The delimiter must be a String, the collectionType must be a FQN and the
itemConverter can be anything which is acceptable by Faces.createConverter(Object).
<h:inputText value="#{bean.uniqueOrderedSemiColonSeparatedNumbers}">
<o:toCollectionConverter delimiter=";"
collectionType="java.util.TreeSet"
itemConverter="jakarta.faces.Integer" />
</h:inputText>
- Since:
- 2.6
- Author:
- Bauke Scholtz
- See Also:
-
Field Summary
Fields inherited from interface jakarta.faces.convert.Converter
DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAsObject(FacesContext context, UIComponent component, String submittedValue) getAsString(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.
-
Constructor Details
-
ToCollectionConverter
public ToCollectionConverter()
-
-
Method Details
-
getAsObject
- Specified by:
getAsObjectin interfaceConverter<Collection>
-
getAsString
- Specified by:
getAsStringin interfaceConverter<Collection>
-
setDelimiter
Sets the delimiter to split on.- Parameters:
delimiter- The delimiter to split on.
-
setCollectionType
Sets the FQN of the collection to create.- Parameters:
collectionType- The FQN of the collection to create.
-
setItemConverter
Sets the converter for the item.- Parameters:
itemConverter- The converter for the item.
-