Class StringToIntegerConverter

  • All Implemented Interfaces:
    Converter<java.lang.String,​java.lang.Integer>, java.io.Serializable

    public class StringToIntegerConverter
    extends AbstractStringToNumberConverter<java.lang.Integer>
    A converter that converts from String to Integer and back. Uses the given locale and a NumberFormat instance for formatting and parsing.

    Override and overwrite getFormat(Locale) to use a different format.

    Since:
    8.0
    Author:
    Vaadin Ltd
    See Also:
    Serialized Form
    • Constructor Detail

      • StringToIntegerConverter

        public StringToIntegerConverter​(java.lang.String errorMessage)
        Creates a new converter instance with the given error message. Empty strings are converted to null.
        Parameters:
        errorMessage - the error message to use if conversion fails
      • StringToIntegerConverter

        public StringToIntegerConverter​(java.lang.Integer 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
      • StringToIntegerConverter

        public StringToIntegerConverter​(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
        Since:
        8.4
      • StringToIntegerConverter

        public StringToIntegerConverter​(java.lang.Integer 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
    • Method Detail

      • convertToModel

        public Result<java.lang.Integer> convertToModel​(java.lang.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.

        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