Package com.vaadin.data.converter
Class StringToIntegerConverter
- java.lang.Object
-
- com.vaadin.data.converter.AbstractStringToNumberConverter<java.lang.Integer>
-
- com.vaadin.data.converter.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 fromStringtoIntegerand back. Uses the given locale and aNumberFormatinstance 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 Summary
Constructors Constructor Description StringToIntegerConverter(ErrorMessageProvider errorMessageProvider)Creates a new converter instance with the given error message provider.StringToIntegerConverter(java.lang.Integer emptyValue, ErrorMessageProvider errorMessageProvider)Creates a new converter instance with the given empty string value and error message provider.StringToIntegerConverter(java.lang.Integer emptyValue, java.lang.String errorMessage)Creates a new converter instance with the given empty string value and error message.StringToIntegerConverter(java.lang.String errorMessage)Creates a new converter instance with the given error message.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Result<java.lang.Integer>convertToModel(java.lang.String value, ValueContext context)Converts the given value from model type to presentation type.protected java.text.NumberFormatgetFormat(java.util.Locale locale)Returns the format used byConverter.convertToPresentation(Object, ValueContext)andconvertToModel(String, ValueContext).-
Methods inherited from class com.vaadin.data.converter.AbstractStringToNumberConverter
convertToNumber, convertToPresentation, getErrorMessage
-
-
-
-
Constructor Detail
-
StringToIntegerConverter
public StringToIntegerConverter(java.lang.String errorMessage)
Creates a new converter instance with the given error message. Empty strings are converted tonull.- 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 benullerrorMessage- 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 tonull.- 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 benullerrorMessageProvider- the error message provider to use if conversion fails- Since:
- 8.4
-
-
Method Detail
-
getFormat
protected java.text.NumberFormat getFormat(java.util.Locale locale)
Returns the format used byConverter.convertToPresentation(Object, ValueContext)andconvertToModel(String, ValueContext).- Overrides:
getFormatin classAbstractStringToNumberConverter<java.lang.Integer>- Parameters:
locale- The locale to use- Returns:
- A NumberFormat instance
-
convertToModel
public Result<java.lang.Integer> convertToModel(java.lang.String value, ValueContext context)
Description copied from interface:ConverterConverts 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 nullcontext- The value context for the conversion.- Returns:
- The converted value compatible with the source type
-
-