public class StringToBooleanConverter extends Object implements Converter<String,Boolean>
String to Boolean and back.
The String representation is given by Boolean.toString() or provided
in constructor StringToBooleanConverter(String, String).
Leading and trailing white spaces are ignored when converting from a String.
For language-dependent representation, subclasses should overwrite
getFalseString(Locale) and getTrueString(Locale)
Converter.ConversionException| Constructor and Description |
|---|
StringToBooleanConverter()
Creates converter with default string representations - "true" and
"false"
|
StringToBooleanConverter(String trueString,
String falseString)
Creates converter with custom string representation.
|
| Modifier and Type | Method and Description |
|---|---|
Boolean |
convertToModel(String value,
Class<? extends Boolean> targetType,
Locale locale)
Converts the given value from target type to source type.
|
String |
convertToPresentation(Boolean value,
Class<? extends String> targetType,
Locale locale)
Converts the given value from source type to target type.
|
protected String |
getFalseString()
Gets the string representation for false.
|
protected String |
getFalseString(Locale locale)
Gets the locale-depended string representation for false.
|
Class<Boolean> |
getModelType()
The source type of the converter.
|
Class<String> |
getPresentationType()
The target type of the converter.
|
protected String |
getTrueString()
Gets the string representation for true.
|
protected String |
getTrueString(Locale locale)
Gets the locale-depended string representation for true.
|
public StringToBooleanConverter()
public Boolean convertToModel(String value, Class<? extends Boolean> targetType, Locale locale) throws Converter.ConversionException
ConverterA converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingConverter.convertToPresentation(Object, Class, Locale) and
Converter.convertToModel(Object, Class, Locale) should return the original
value.convertToModel in interface Converter<String,Boolean>value - The value to convert, compatible with the target type. Can be
nulltargetType - The requested type of the return valuelocale - The locale to use for conversion. Can be null.Converter.ConversionException - If the value could not be convertedprotected String getTrueString()
protected String getFalseString()
public String convertToPresentation(Boolean value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException
ConverterA converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingConverter.convertToPresentation(Object, Class, Locale) and
Converter.convertToModel(Object, Class, Locale) should return the original
value.convertToPresentation in interface Converter<String,Boolean>value - The value to convert, compatible with the target type. Can be
nulltargetType - The requested type of the return valuelocale - The locale to use for conversion. Can be null.Converter.ConversionException - If the value could not be convertedprotected String getFalseString(Locale locale)
getFalseString()locale - to be usedprotected String getTrueString(Locale locale)
getTrueString()locale - to be usedpublic Class<Boolean> getModelType()
ConverterConverter.convertToPresentation(Object, Class, Locale).getModelType in interface Converter<String,Boolean>public Class<String> getPresentationType()
ConverterConverter.convertToModel(Object, Class, Locale).getPresentationType in interface Converter<String,Boolean>Copyright © 2016 Vaadin Ltd. All rights reserved.