public class ToCollectionConverter extends TrimConverter
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.
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" />
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.
You can use <o:converter>
to specify those attributes. 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:converter converterId="omnifaces.ToCollectionConverter" delimiter=";" collectionType="java.util.TreeSet" itemConverter="javax.faces.Integer" > </h:inputText>
TrimConverter
DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME
Constructor and Description |
---|
ToCollectionConverter() |
Modifier and Type | Method and Description |
---|---|
Object |
getAsObject(FacesContext context,
UIComponent component,
String submittedValue) |
String |
getAsString(FacesContext context,
UIComponent component,
Object modelValue) |
void |
setCollectionType(String collectionType) |
void |
setDelimiter(String delimiter) |
void |
setItemConverter(Object itemConverter) |
public Object getAsObject(FacesContext context, UIComponent component, String submittedValue)
getAsObject
in interface Converter
getAsObject
in class TrimConverter
public String getAsString(FacesContext context, UIComponent component, Object modelValue)
getAsString
in interface Converter
getAsString
in class TrimConverter
public void setDelimiter(String delimiter)
public void setCollectionType(String collectionType)
public void setItemConverter(Object itemConverter)
Copyright © 2012–2017 OmniFaces. All rights reserved.