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, 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)
| Constructor and Description |
|---|
StringToBooleanConverter(String errorMessage)
Creates converter with default string representations - "true" and
"false".
|
StringToBooleanConverter(String errorMessage,
String trueString,
String falseString)
Creates converter with custom string representation.
|
| Modifier and Type | Method and Description |
|---|---|
Result<Boolean> |
convertToModel(String value,
ValueContext context)
Converts the given value from model type to presentation type.
|
String |
convertToPresentation(Boolean value,
ValueContext context)
Converts the given value from presentation type to model type.
|
protected String |
getFalseString(Locale locale)
Gets the locale-depended string representation for false.
|
protected String |
getTrueString(Locale locale)
Gets the locale-depended string representation for true.
|
public StringToBooleanConverter(String errorMessage)
errorMessage - the error message to use if conversion failspublic StringToBooleanConverter(String errorMessage, String trueString, String falseString)
errorMessage - the error message to use if conversion failsfalseString - string representation for falsetrueString - string representation for truepublic Result<Boolean> convertToModel(String value, ValueContext context)
ConverterA converter can optionally use locale to do the conversion.
convertToModel in interface Converter<String,Boolean>value - The value to convert. Can be nullcontext - The value context for the conversion.public String convertToPresentation(Boolean value, ValueContext context)
ConverterA converter can optionally use locale to do the conversion.
convertToPresentation in interface Converter<String,Boolean>value - The value to convert. Can be nullcontext - The value context for the conversion.protected String getFalseString(Locale locale)
falselocale - to be usedCopyright © 2017 Vaadin Ltd. All rights reserved.