Package com.vaadin.data.converter
Class StringToBigDecimalConverter
- java.lang.Object
-
- com.vaadin.data.converter.AbstractStringToNumberConverter<BigDecimal>
-
- com.vaadin.data.converter.StringToBigDecimalConverter
-
- All Implemented Interfaces:
Converter<String,BigDecimal>,Serializable
public class StringToBigDecimalConverter extends AbstractStringToNumberConverter<BigDecimal>
A converter that converts fromStringtoBigDecimaland back. Uses the given locale and aNumberFormatinstance for formatting and parsing.Leading and trailing white spaces are ignored when converting from a String.
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 StringToBigDecimalConverter(ErrorMessageProvider errorMessageProvider)Creates a new converter instance with the given error message provider.StringToBigDecimalConverter(String errorMessage)Creates a new converter instance with the given error message.StringToBigDecimalConverter(BigDecimal emptyValue, ErrorMessageProvider errorMessageProvider)Creates a new converter instance with the given empty string value and error message provider.StringToBigDecimalConverter(BigDecimal emptyValue, String errorMessage)Creates a new converter instance with the given empty string value and error message.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Result<BigDecimal>convertToModel(String value, ValueContext context)Converts the given value from model type to presentation type.protected NumberFormatgetFormat(Locale locale)Returns the format used byConverter.convertToPresentation(Object, ValueContext)andConverter.convertToModel(Object, ValueContext).-
Methods inherited from class com.vaadin.data.converter.AbstractStringToNumberConverter
convertToNumber, convertToPresentation, getErrorMessage
-
-
-
-
Constructor Detail
-
StringToBigDecimalConverter
public StringToBigDecimalConverter(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
-
StringToBigDecimalConverter
public StringToBigDecimalConverter(BigDecimal emptyValue, 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
-
StringToBigDecimalConverter
public StringToBigDecimalConverter(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
-
StringToBigDecimalConverter
public StringToBigDecimalConverter(BigDecimal 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 NumberFormat getFormat(Locale locale)
Description copied from class:AbstractStringToNumberConverterReturns the format used byConverter.convertToPresentation(Object, ValueContext)andConverter.convertToModel(Object, ValueContext).- Overrides:
getFormatin classAbstractStringToNumberConverter<BigDecimal>- Parameters:
locale- The locale to use- Returns:
- A NumberFormat instance
-
convertToModel
public Result<BigDecimal> convertToModel(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
-
-