Class AbstractStringToNumberConverter<T extends java.lang.Number>

    • Constructor Detail

      • AbstractStringToNumberConverter

        protected AbstractStringToNumberConverter​(T emptyValue,
                                                  ErrorMessageProvider errorMessageProvider)
        Creates a new converter instance with the given empty string value 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
        Since:
        8.4
      • AbstractStringToNumberConverter

        protected AbstractStringToNumberConverter​(T emptyValue,
                                                  java.lang.String errorMessage)
        Creates a new converter instance with the given empty string value 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<java.lang.Number> convertToNumber​(java.lang.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 java.lang.String getErrorMessage​(ValueContext context)
        Gets the error message to use when conversion fails.
        Returns:
        the error message
      • convertToPresentation

        public java.lang.String convertToPresentation​(T 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<java.lang.String,​T extends java.lang.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