Package org.springframework.beans.propertyeditors

# Class StringTrimmerEditor

java.lang.Object
java.beans.PropertyEditorSupport
org.springframework.beans.propertyeditors.StringTrimmerEditor

All Implemented Interfaces:
  `PropertyEditor`

public class StringTrimmerEditor extends PropertyEditorSupport
Property editor that trims Strings.

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

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

## Constructor Summary

Constructors
Constructor
Description
`StringTrimmerEditor(boolean emptyAsNull)`
Create a new StringTrimmerEditor.
`StringTrimmerEditor(String charsToDelete, boolean emptyAsNull)`
Create a new StringTrimmerEditor.

## Method Summary

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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### StringTrimmerEditor

public StringTrimmerEditor(boolean emptyAsNull)
Create a new StringTrimmerEditor.

Parameters:
  `emptyAsNull` - `true` if an empty String is to be transformed into `null`

### StringTrimmerEditor

public StringTrimmerEditor(String charsToDelete, boolean emptyAsNull)
Create a new StringTrimmerEditor.

Parameters:
  `charsToDelete` - a set of characters to delete, in addition to trimming an input String. Useful for deleting unwanted line breaks: for example, "\r\n\f" will delete all new lines and line feeds in a String.
  `emptyAsNull` - `true` if an empty String is to be transformed into `null`

## Method Details

### setAsText

public void setAsText(@Nullable String text)

Specified by:
  `setAsText` in interface `PropertyEditor`
Overrides:
  `setAsText` in class `PropertyEditorSupport`

### getAsText

public String getAsText()

Specified by:
  `getAsText` in interface `PropertyEditor`
Overrides:
  `getAsText` in class `PropertyEditorSupport`