Package com.vaadin.data.converter
Class StringToBooleanConverter
- java.lang.Object
-
- com.vaadin.data.converter.StringToBooleanConverter
-
- All Implemented Interfaces:
Converter<String,Boolean>,Serializable
public class StringToBooleanConverter extends Object implements Converter<String,Boolean>
A converter that converts fromStringtoBooleanand back. The String representation is given byBoolean.toString()or provided in constructorStringToBooleanConverter(String, String, String).Leading and trailing white spaces are ignored when converting from a String.
For language-dependent representation, subclasses should overwrite
getFalseString(Locale)andgetTrueString(Locale)- Since:
- 8.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Result<Boolean>convertToModel(String value, ValueContext context)Converts the given value from model type to presentation type.StringconvertToPresentation(Boolean value, ValueContext context)Converts the given value from presentation type to model type.protected StringgetFalseString(Locale locale)Gets the locale-depended string representation for false.protected StringgetTrueString(Locale locale)Gets the locale-depended string representation for true.
-
-
-
Constructor Detail
-
StringToBooleanConverter
public StringToBooleanConverter(String errorMessage)
Creates converter with default string representations - "true" and "false".- Parameters:
errorMessage- the error message to use if conversion fails
-
StringToBooleanConverter
public StringToBooleanConverter(ErrorMessageProvider errorMessageProvider)
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- Since:
- 8.4
-
StringToBooleanConverter
public StringToBooleanConverter(String errorMessage, String trueString, String falseString)
Creates converter with custom string representation.- Parameters:
errorMessage- the error message to use if conversion failsfalseString- string representation forfalsetrueString- string representation fortrue
-
StringToBooleanConverter
public StringToBooleanConverter(String trueString, String falseString, ErrorMessageProvider errorMessageProvider)
Creates converter with custom string representation.- Parameters:
falseString- string representation forfalsetrueString- string representation fortrueerrorMessageProvider- the error message provider to use if conversion fails- Since:
- 8.4
-
-
Method Detail
-
convertToModel
public Result<Boolean> convertToModel(String value, ValueContext context)
Description copied from interface:ConverterConverts the given value from model type to presentation type.A converter can optionally use locale to do the conversion.
- Specified by:
convertToModelin 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
public String convertToPresentation(Boolean value, ValueContext context)
Description copied from interface:ConverterConverts the given value from presentation type to model type.A converter can optionally use locale to do the conversion.
- Specified by:
convertToPresentationin 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
protected String getFalseString(Locale locale)
Gets the locale-depended string representation for false. Default is locale-independent valuefalse- Parameters:
locale- to be used- Returns:
- the string representation for false
-
-