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

public Class CustomBooleanEditor

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

Property editor for Boolean/boolean properties.

This is not meant to be used as system PropertyEditor but rather as locale-specific Boolean editor within custom controller code, to parse UI-caused boolean strings into boolean properties of beans and check them in the UI form.

In web MVC code, this editor will typically be registered with binder.registerCustomEditor calls.

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

Field Summary

Modifier and TypeField and Description
private final boolean
private final String
private final String
public static final String
VALUE_0

Value of "0".

public static final String
VALUE_1

Value of "1".

public static final String
VALUE_FALSE

Value of "false".

public static final String
VALUE_NO

Value of "no".

public static final String
VALUE_OFF

Value of "off".

public static final String
VALUE_ON

Value of "on".

public static final String
VALUE_TRUE

Value of "true".

public static final String
VALUE_YES

Value of "yes".

Constructor Summary

AccessConstructor and Description
public
CustomBooleanEditor(boolean
if empty strings should be allowed
allowEmpty
)

Create a new CustomBooleanEditor instance, with "true"/"on"/"yes" and "false"/"off"/"no" as recognized String values.

public
CustomBooleanEditor(String
the String value that represents true: for example, "true" (VALUE_TRUE), "on" (VALUE_ON), "yes" (VALUE_YES) or some custom value
trueString
,
String
the String value that represents false: for example, "false" (VALUE_FALSE), "off" (VALUE_OFF), "no" (VALUE_NO) or some custom value
falseString
,
boolean
if empty strings should be allowed
allowEmpty
)

Create a new CustomBooleanEditor instance, with configurable String values for true and false.

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

allowEmptyback to summary
private final boolean allowEmpty
falseStringback to summary
private final String falseString
Annotations
@Nullable
trueStringback to summary
private final String trueString
Annotations
@Nullable
VALUE_0back to summary
public static final String VALUE_0

Value of "0".

VALUE_1back to summary
public static final String VALUE_1

Value of "1".

VALUE_FALSEback to summary
public static final String VALUE_FALSE

Value of "false".

VALUE_NOback to summary
public static final String VALUE_NO

Value of "no".

VALUE_OFFback to summary
public static final String VALUE_OFF

Value of "off".

VALUE_ONback to summary
public static final String VALUE_ON

Value of "on".

VALUE_TRUEback to summary
public static final String VALUE_TRUE

Value of "true".

VALUE_YESback to summary
public static final String VALUE_YES

Value of "yes".

Constructor Detail

CustomBooleanEditorback to summary
public CustomBooleanEditor(boolean allowEmpty)

Create a new CustomBooleanEditor instance, with "true"/"on"/"yes" and "false"/"off"/"no" as recognized String values.

The "allowEmpty" parameter states if an empty String should be allowed for parsing, i.e. get interpreted as null value. Else, an IllegalArgumentException gets thrown in that case.

Parameters
allowEmpty:boolean

if empty strings should be allowed

CustomBooleanEditorback to summary
public CustomBooleanEditor(String trueString, String falseString, boolean allowEmpty)

Create a new CustomBooleanEditor instance, with configurable String values for true and false.

The "allowEmpty" parameter states if an empty String should be allowed for parsing, i.e. get interpreted as null value. Else, an IllegalArgumentException gets thrown in that case.

Parameters
trueString:String

the String value that represents true: for example, "true" (VALUE_TRUE), "on" (VALUE_ON), "yes" (VALUE_YES) or some custom value

falseString:String

the String value that represents false: for example, "false" (VALUE_FALSE), "off" (VALUE_OFF), "no" (VALUE_NO) or some custom value

allowEmpty:boolean

if empty strings should be allowed

See Also
VALUE_TRUE, VALUE_FALSE, VALUE_ON, VALUE_OFF, VALUE_YES, VALUE_NO

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) throws IllegalArgumentException

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