public class StringToDateConverter extends Object implements Converter<String,Date>
Date
to String
and back. Uses
the given locale and DateFormat
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.
Converter.ConversionException
Constructor and Description |
---|
StringToDateConverter() |
Modifier and Type | Method and Description |
---|---|
Date |
convertToModel(String value,
Class<? extends Date> targetType,
Locale locale)
Converts the given value from target type to source type.
|
String |
convertToPresentation(Date value,
Class<? extends String> targetType,
Locale locale)
Converts the given value from source type to target type.
|
protected DateFormat |
getFormat(Locale locale)
Returns the format used by
convertToPresentation(Date, Class,Locale) and
convertToModel(String, Class, Locale) . |
Class<Date> |
getModelType()
The source type of the converter.
|
Class<String> |
getPresentationType()
The target type of the converter.
|
protected DateFormat getFormat(Locale locale)
convertToPresentation(Date, Class,Locale)
and
convertToModel(String, Class, Locale)
.locale
- The locale to usepublic Date convertToModel(String value, Class<? extends Date> targetType, Locale locale) throws Converter.ConversionException
Converter
A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingConverter.convertToPresentation(Object, Class, Locale)
and
Converter.convertToModel(Object, Class, Locale)
should return the original
value.convertToModel
in interface Converter<String,Date>
value
- The value to convert, compatible with the target type. Can be
nulltargetType
- The requested type of the return valuelocale
- The locale to use for conversion. Can be null.Converter.ConversionException
- If the value could not be convertedpublic String convertToPresentation(Date value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException
Converter
A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingConverter.convertToPresentation(Object, Class, Locale)
and
Converter.convertToModel(Object, Class, Locale)
should return the original
value.convertToPresentation
in interface Converter<String,Date>
value
- The value to convert, compatible with the target type. Can be
nulltargetType
- The requested type of the return valuelocale
- The locale to use for conversion. Can be null.Converter.ConversionException
- If the value could not be convertedpublic Class<Date> getModelType()
Converter
Converter.convertToPresentation(Object, Class, Locale)
.getModelType
in interface Converter<String,Date>
public Class<String> getPresentationType()
Converter
Converter.convertToModel(Object, Class, Locale)
.getPresentationType
in interface Converter<String,Date>
Copyright © 2021 Vaadin Ltd. All rights reserved.