Class StringToBooleanConverter
java.lang.Object
com.vaadin.featurepack.data.converter.StringToBooleanConverter
- All Implemented Interfaces:
Converter<String,,Boolean> com.vaadin.flow.data.converter.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).
Leading and trailing white spaces are ignored when converting from a String.
For language-dependent representation, subclasses should overwrite
getFalseString(Locale) and getTrueString(Locale)
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.featurepack.data.converter.Converter
Converter.ConversionException -
Constructor Summary
ConstructorsConstructorDescriptionCreates converter with default string representations - "true" and "false"StringToBooleanConverter(String trueString, String falseString) Creates converter with custom string representation. -
Method Summary
Modifier and TypeMethodDescriptionconvertToModel(String value, Class<? extends Boolean> targetType, Locale locale) Converts the given value from target type to source type.convertToPresentation(Boolean value, Class<? extends String> targetType, Locale locale) Converts the given value from source type to target type.protected StringGets the string representation for false.protected StringgetFalseString(Locale locale) Gets the locale-depended string representation for false.The source type of the converter.The target type of the converter.protected StringGets the string representation for true.protected StringgetTrueString(Locale locale) Gets the locale-depended string representation for true.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.featurepack.data.converter.Converter
convertToModel, convertToPresentationMethods inherited from interface com.vaadin.flow.data.converter.Converter
chain
-
Constructor Details
-
StringToBooleanConverter
public StringToBooleanConverter()Creates converter with default string representations - "true" and "false" -
StringToBooleanConverter
Creates converter with custom string representation.- Parameters:
trueString- string representation fortruefalseString- string representation forfalse- Since:
- 7.5.4
-
-
Method Details
-
convertToModel
public Boolean convertToModel(String value, Class<? extends Boolean> targetType, Locale locale) throws Converter.ConversionException Description copied from interface:ConverterConverts the given value from target type to source type.A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingConverter.convertToPresentation(Object, Class, Locale)andConverter.convertToModel(Object, Class, Locale)should return the original value.- Specified by:
convertToModelin interfaceConverter<String,Boolean> - Parameters:
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.- Returns:
- The converted value compatible with the source type
- Throws:
Converter.ConversionException- If the value could not be converted
-
getTrueString
Gets the string representation for true. Default is "true", if not set in constructor.- Returns:
- the string representation for true
-
getFalseString
Gets the string representation for false. Default is "false", if not set in constructor.- Returns:
- the string representation for false
-
convertToPresentation
public String convertToPresentation(Boolean value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException Description copied from interface:ConverterConverts the given value from source type to target type.A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingConverter.convertToPresentation(Object, Class, Locale)andConverter.convertToModel(Object, Class, Locale)should return the original value.- Specified by:
convertToPresentationin interfaceConverter<String,Boolean> - Parameters:
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.- Returns:
- The converted value compatible with the source type
- Throws:
Converter.ConversionException- If the value could not be converted
-
getFalseString
Gets the locale-depended string representation for false. Default is locale-independent value provided bygetFalseString()- Parameters:
locale- to be used- Returns:
- the string representation for false
- Since:
- 7.5.4
-
getTrueString
Gets the locale-depended string representation for true. Default is locale-independent value provided bygetTrueString()- Parameters:
locale- to be used- Returns:
- the string representation for true
- Since:
- 7.5.4
-
getModelType
Description copied from interface:ConverterThe source type of the converter. Values of this type can be passed toConverter.convertToPresentation(Object, Class, Locale).- Specified by:
getModelTypein interfaceConverter<String,Boolean> - Returns:
- The source type
-
getPresentationType
Description copied from interface:ConverterThe target type of the converter. Values of this type can be passed toConverter.convertToModel(Object, Class, Locale).- Specified by:
getPresentationTypein interfaceConverter<String,Boolean> - Returns:
- The target type
-