You're viewing an older version of Vaadin JavaDoc. Please see version 24.7.0 for the latest.
com.vaadin.flow.data.converter.

Class AbstractStringToNumberConverter<T extends Number>

  • java.lang.Object
    • com.vaadin.flow.data.converter.AbstractStringToNumberConverter<T>
    • Constructor Detail

      • AbstractStringToNumberConverter

        protected AbstractStringToNumberConverter​(T emptyValue,
                                                  ErrorMessageProvider errorMessageProvider)

        Creates a new converter instance with the given presentation value for empty string and error message provider.

        Parameters:

        emptyValue - the presentation value to return when converting an empty string, may be null

        errorMessageProvider - the error message provider to use if conversion fails

      • AbstractStringToNumberConverter

        protected AbstractStringToNumberConverter​(T emptyValue,
                                                  String errorMessage)

        Creates a new converter instance with the given presentation value for empty string and error message.

        Parameters:

        emptyValue - the presentation value to return when converting an empty string, may be null

        errorMessage - the error message to use if conversion fails

    • Method Detail

      • convertToNumber

        protected Result<Number> convertToNumber​(String value,
                                                 ValueContext context)

        Convert the value to a Number using the given locale and getFormat(Locale).

        Parameters:

        value - The value to convert

        context - The value context for conversion

        Returns:

        The converted value

      • getErrorMessage

        protected String getErrorMessage​(ValueContext context)

        Gets the error message to use when conversion fails.

        Parameters:

        context - The value context for generating the error message

        Returns:

        the error message

      • convertToPresentation

        public String convertToPresentation​(T 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:

        convertToPresentation in interface Converter<String,​T extends Number>

        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