Top Description Fields Constructors Methods
org.springframework.beans.propertyeditors

public Class StringTrimmerEditor

extends PropertyEditorSupport
Class Inheritance
Imports
java.beans.PropertyEditorSupport, org.springframework.lang.Nullable, org.springframework.util.StringUtils

Property editor that trims Strings.

Optionally allows transforming an empty string into a null value. Needs to be explicitly registered, e.g. for command binding.

Author
Juergen Hoeller
See Also
org.springframework.validation.DataBinder#registerCustomEditor

Field Summary

Modifier and TypeField and Description
private final String
private final boolean

Constructor Summary

AccessConstructor and Description
public
StringTrimmerEditor(boolean
true if an empty String is to be transformed into null
emptyAsNull
)

Create a new StringTrimmerEditor.

public
StringTrimmerEditor(String
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.
charsToDelete
,
boolean
true if an empty String is to be transformed into null
emptyAsNull
)

Create a new StringTrimmerEditor.

Method Summary

Modifier and TypeMethod and Description
public String
getAsText()

Overrides java.beans.PropertyEditorSupport.getAsText.

Implements java.beans.PropertyEditor.getAsText.

Gets the property value as a string suitable for presentation to a human to edit.

public void
setAsText(String
The string to be parsed.
text
)

Overrides java.beans.PropertyEditorSupport.setAsText.

Implements java.beans.PropertyEditor.setAsText.

Sets the property value by parsing a given String.

Inherited from java.beans.PropertyEditorSupport:
addPropertyChangeListenerfirePropertyChangegetCustomEditorgetJavaInitializationStringgetSourcegetTagsgetValueisPaintablepaintValueremovePropertyChangeListenersetSourcesetValuesupportsCustomEditor

Field Detail

charsToDeleteback to summary
private final String charsToDelete
Annotations
@Nullable
emptyAsNullback to summary
private final boolean emptyAsNull

Constructor Detail

StringTrimmerEditorback to summary
public StringTrimmerEditor(boolean emptyAsNull)

Create a new StringTrimmerEditor.

Parameters
emptyAsNull:boolean

true if an empty String is to be transformed into null

StringTrimmerEditorback to summary
public StringTrimmerEditor(String charsToDelete, boolean emptyAsNull)

Create a new StringTrimmerEditor.

Parameters
charsToDelete:String

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.

emptyAsNull:boolean

true if an empty String is to be transformed into null

Method Detail

getAsTextback to summary
public String getAsText()

Overrides java.beans.PropertyEditorSupport.getAsText.

Implements java.beans.PropertyEditor.getAsText.

Doc from java.beans.PropertyEditorSupport.getAsText.

Gets the property value as a string suitable for presentation to a human to edit.

Returns:String

The property value as a string suitable for presentation to a human to edit.

Returns null if the value can't be expressed as a string.

If a non-null value is returned, then the PropertyEditor should be prepared to parse that string back in setAsText().

Annotations
@Override
setAsTextback to summary
public void setAsText(String text)

Overrides java.beans.PropertyEditorSupport.setAsText.

Implements java.beans.PropertyEditor.setAsText.

Doc from java.beans.PropertyEditorSupport.setAsText.

Sets the property value by parsing a given String. May raise java.lang.IllegalArgumentException if either the String is badly formatted or if this kind of property can't be expressed as text.

Parameters
text:String

The string to be parsed.

Annotations
@Override