com.vaadin.flow.data.converter.

Class StringToBooleanConverter

    • 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 to null.

        Parameters:

        errorMessageProvider - the error message provider to use if conversion fails

      • StringToBooleanConverter

        public StringToBooleanConverter(String errorMessage,
                                        String trueString,
                                        String falseString)

        Creates converter with custom string representation.

        Parameters:

        errorMessage - the error message to use if conversion fails

        falseString - string representation for false

        trueString - string representation for true

      • StringToBooleanConverter

        public StringToBooleanConverter(String trueString,
                                        String falseString,
                                        ErrorMessageProvider errorMessageProvider)

        Creates converter with custom string representation.

        Parameters:

        falseString - string representation for false

        trueString - string representation for true

        errorMessageProvider - the error message provider to use if conversion fails

    • Method Detail

      • convertToModel

        public Result<Boolean> convertToModel(String value,
                                              ValueContext context)

        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:

        convertToModel in interface Converter<String,Boolean>

        Parameters:

        value - The value to convert. Can be null

        context - 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: Converter

        Converts the given value from presentation type to model type.

        A converter can optionally use locale to do the conversion.

        Specified by:

        convertToPresentation in interface Converter<String,Boolean>

        Parameters:

        value - The value to convert. Can be null

        context - 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 value false

        Parameters:

        locale - to be used

        Returns:

        the string representation for false

      • getTrueString

        protected String getTrueString(Locale locale)

        Gets the locale-depended string representation for true. Default is locale-independent value true

        Parameters:

        locale - to be used

        Returns:

        the string representation for true