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(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.
|
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(ErrorMessageProvider errorMessageProvider)
null
.errorMessageProvider
- the error message provider to use if conversion failspublic StringToBooleanConverter(String errorMessage, String trueString, String falseString)
errorMessage
- the error message to use if conversion failsfalseString
- string representation for false
trueString
- string representation for true
public StringToBooleanConverter(String trueString, String falseString, ErrorMessageProvider errorMessageProvider)
falseString
- string representation for false
trueString
- string representation for true
errorMessageProvider
- the error message provider to use if conversion failspublic Result<Boolean> convertToModel(String value, ValueContext context)
Converter
A 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)
Converter
A 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)
false
locale
- to be usedCopyright © 2019. All rights reserved.