Class StringArrayPropertyEditor
- java.lang.Object
- java.beans.PropertyEditorSupport
- org.springframework.beans.propertyeditors.StringArrayPropertyEditor
- All Implemented Interfaces:
PropertyEditor
public class StringArrayPropertyEditor extends PropertyEditorSupport
CustomPropertyEditor
for String arrays.Strings must be in CSV format, with a customizable separator. By default values in the result are trimmed of whitespace.
- Author:
- Rod Johnson, Juergen Hoeller, Dave Syer
- See Also:
StringUtils.delimitedListToStringArray(java.lang.String, java.lang.String)
,StringUtils.arrayToDelimitedString(java.lang.Object[], java.lang.String)
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_SEPARATOR
Default separator for splitting a String: a comma (",").
Constructor Summary
Constructors Constructor Description StringArrayPropertyEditor()
Create a newStringArrayPropertyEditor
with the default separator (a comma).StringArrayPropertyEditor(String separator)
Create a newStringArrayPropertyEditor
with the given separator.StringArrayPropertyEditor(String separator, boolean emptyArrayAsNull)
Create a newStringArrayPropertyEditor
with the given separator.StringArrayPropertyEditor(String separator, boolean emptyArrayAsNull, boolean trimValues)
Create a newStringArrayPropertyEditor
with the given separator.StringArrayPropertyEditor(String separator, String charsToDelete, boolean emptyArrayAsNull)
Create a newStringArrayPropertyEditor
with the given separator.StringArrayPropertyEditor(String separator, String charsToDelete, boolean emptyArrayAsNull, boolean trimValues)
Create a newStringArrayPropertyEditor
with the given separator.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getAsText()
void
setAsText(String text)
Methods inherited from class java.beans.PropertyEditorSupport
addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setSource, setValue, supportsCustomEditor
Field Detail
DEFAULT_SEPARATOR
public static final String DEFAULT_SEPARATOR
Default separator for splitting a String: a comma (",").- See Also:
- Constant Field Values
Constructor Detail
StringArrayPropertyEditor
public StringArrayPropertyEditor()
Create a newStringArrayPropertyEditor
with the default separator (a comma).An empty text (without elements) will be turned into an empty array.
StringArrayPropertyEditor
public StringArrayPropertyEditor(String separator)
Create a newStringArrayPropertyEditor
with the given separator.An empty text (without elements) will be turned into an empty array.
- Parameters:
separator
- the separator to use for splitting aString
StringArrayPropertyEditor
public StringArrayPropertyEditor(String separator, boolean emptyArrayAsNull)
Create a newStringArrayPropertyEditor
with the given separator.- Parameters:
separator
- the separator to use for splitting aString
emptyArrayAsNull
-true
if an empty String array is to be transformed intonull
StringArrayPropertyEditor
public StringArrayPropertyEditor(String separator, boolean emptyArrayAsNull, boolean trimValues)
Create a newStringArrayPropertyEditor
with the given separator.- Parameters:
separator
- the separator to use for splitting aString
emptyArrayAsNull
-true
if an empty String array is to be transformed intonull
trimValues
-true
if the values in the parsed arrays are to be trimmed of whitespace (default is true)
StringArrayPropertyEditor
public StringArrayPropertyEditor(String separator, @Nullable String charsToDelete, boolean emptyArrayAsNull)
Create a newStringArrayPropertyEditor
with the given separator.- Parameters:
separator
- the separator to use for splitting aString
charsToDelete
- a set of characters to delete, in addition to trimming an input String. Useful for deleting unwanted line breaks: e.g. "\r\n\f" will delete all new lines and line feeds in a String.emptyArrayAsNull
-true
if an empty String array is to be transformed intonull
StringArrayPropertyEditor
public StringArrayPropertyEditor(String separator, @Nullable String charsToDelete, boolean emptyArrayAsNull, boolean trimValues)
Create a newStringArrayPropertyEditor
with the given separator.- Parameters:
separator
- the separator to use for splitting aString
charsToDelete
- a set of characters to delete, in addition to trimming an input String. Useful for deleting unwanted line breaks: e.g. "\r\n\f" will delete all new lines and line feeds in a String.emptyArrayAsNull
-true
if an empty String array is to be transformed intonull
trimValues
-true
if the values in the parsed arrays are to be trimmed of whitespace (default is true)
Method Detail
setAsText
public void setAsText(String text) throws IllegalArgumentException
- Specified by:
setAsText
in interfacePropertyEditor
- Overrides:
setAsText
in classPropertyEditorSupport
- Throws:
IllegalArgumentException
getAsText
public String getAsText()
- Specified by:
getAsText
in interfacePropertyEditor
- Overrides:
getAsText
in classPropertyEditorSupport