com.vaadin.flow.data.converter.
Class StringToFloatConverter
- java.lang.Object
-
- com.vaadin.flow.data.converter.AbstractStringToNumberConverter<Float>
-
- com.vaadin.flow.data.converter.StringToFloatConverter
-
All Implemented Interfaces:
public class StringToFloatConverter extends AbstractStringToNumberConverter<Float>
A converter that converts from
String
toFloat
and back. Uses the given locale and aNumberFormat
instance for formatting and parsing.Leading and trailing white spaces are ignored when converting from a String.
Override and overwrite
AbstractStringToNumberConverter.getFormat(Locale)
to use a different format.Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor and Description StringToFloatConverter(ErrorMessageProvider errorMessageProvider)
Creates a new converter instance with the given error message provider.
StringToFloatConverter(Float emptyValue, ErrorMessageProvider errorMessageProvider)
Creates a new converter instance with the given presentation value for empty string and error message provider.
StringToFloatConverter(Float emptyValue, String errorMessage)
Creates a new converter instance with the given presentation value for empty string and error message.
StringToFloatConverter(String errorMessage)
Creates a new converter instance with the given error message.
-
Method Summary
All Methods Modifier and Type Method and Description Result<Float>
convertToModel(String value, ValueContext context)
Converts the given value from presentation type to model type.
-
Methods inherited from class com.vaadin.flow.data.converter.AbstractStringToNumberConverter
convertToNumber, convertToPresentation, getErrorMessage, getFormat
-
-
-
-
Constructor Detail
-
StringToFloatConverter
public StringToFloatConverter(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
-
StringToFloatConverter
public StringToFloatConverter(Float 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 benull
errorMessage
- the error message to use if conversion fails
-
StringToFloatConverter
public StringToFloatConverter(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
-
StringToFloatConverter
public StringToFloatConverter(Float 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 benull
errorMessageProvider
- the error message provider to use if conversion fails
-
-
Method Detail
-
convertToModel
public Result<Float> convertToModel(String 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.
Parameters:
value
- The value to convert. Can be nullcontext
- The value context for the conversion.Returns:
The converted value compatible with the source type
-
-