Package com.vaadin.flow.data.converter
Class StringToBooleanConverter
java.lang.Object
com.vaadin.flow.data.converter.StringToBooleanConverter
- All Implemented Interfaces:
Converter<String,
,Boolean> Serializable
A converter that converts from
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)
- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
-
Constructor Summary
ConstructorDescriptionStringToBooleanConverter
(ErrorMessageProvider errorMessageProvider) Creates a new converter instance with the given error message provider.StringToBooleanConverter
(String errorMessage) Creates converter with default string representations - "true" and "false".StringToBooleanConverter
(String trueString, String falseString, ErrorMessageProvider errorMessageProvider) Creates converter with custom string representation.StringToBooleanConverter
(String errorMessage, String trueString, String falseString) Creates converter with custom string representation. -
Method Summary
Modifier and TypeMethodDescriptionconvertToModel
(String value, ValueContext context) Converts the given value from presentation type to model type.convertToPresentation
(Boolean value, ValueContext context) Converts the given value from model type to presentation 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.
-
Constructor Details
-
StringToBooleanConverter
Creates converter with default string representations - "true" and "false".- Parameters:
errorMessage
- the error message to use if conversion fails
-
StringToBooleanConverter
Creates a new converter instance with the given error message provider. Empty strings are converted tonull
.- Parameters:
errorMessageProvider
- the error message provider to use if conversion fails
-
StringToBooleanConverter
Creates converter with custom string representation.- Parameters:
errorMessage
- the error message to use if conversion failsfalseString
- string representation forfalse
trueString
- string representation fortrue
-
StringToBooleanConverter
public StringToBooleanConverter(String trueString, String falseString, ErrorMessageProvider errorMessageProvider) Creates converter with custom string representation.- Parameters:
falseString
- string representation forfalse
trueString
- string representation fortrue
errorMessageProvider
- the error message provider to use if conversion fails
-
-
Method Details
-
convertToModel
Description copied from interface:Converter
Converts the given value from presentation type to model type.A converter can optionally use locale to do the conversion.
- Specified by:
convertToModel
in interfaceConverter<String,
Boolean> - Parameters:
value
- The value to convert. Can be nullcontext
- The value context for the conversion.- Returns:
- The converted value compatible with the source type
-
convertToPresentation
Description copied from interface:Converter
Converts the given value from model type to presentation type.A converter can optionally use locale to do the conversion.
- Specified by:
convertToPresentation
in interfaceConverter<String,
Boolean> - Parameters:
value
- The value to convert. Can be nullcontext
- The value context for the conversion.- Returns:
- The converted value compatible with the source type
-
getFalseString
Gets the locale-depended string representation for false. Default is locale-independent valuefalse
- Parameters:
locale
- to be used- Returns:
- the string representation for false
-
getTrueString
Gets the locale-depended string representation for true. Default is locale-independent valuetrue
- Parameters:
locale
- to be used- Returns:
- the string representation for true
-