PRESENTATION
- The presentation type. Must be compatible with what
getPresentationType()
returns.MODEL
- The model type. Must be compatible with what
getModelType()
returns.public interface Converter<PRESENTATION,MODEL> extends Serializable
Typically convertToPresentation(Object, Class, Locale)
and
convertToModel(Object, Class, Locale)
should be symmetric so that
chaining these together returns the original result for all input but this is
not a requirement.
Converters must not have any side effects (never update UI from inside a converter).
All Converters must be stateless and thread safe.
If conversion of a value fails, a Converter.ConversionException
is thrown.
Modifier and Type | Interface and Description |
---|---|
static class |
Converter.ConversionException
An exception that signals that the value passed to
convertToPresentation(Object, Class, Locale) or
convertToModel(Object, Class, Locale) could not be
converted. |
Modifier and Type | Method and Description |
---|---|
MODEL |
convertToModel(PRESENTATION value,
Class<? extends MODEL> targetType,
Locale locale)
Converts the given value from target type to source type.
|
PRESENTATION |
convertToPresentation(MODEL value,
Class<? extends PRESENTATION> targetType,
Locale locale)
Converts the given value from source type to target type.
|
Class<MODEL> |
getModelType()
The source type of the converter.
|
Class<PRESENTATION> |
getPresentationType()
The target type of the converter.
|
MODEL convertToModel(PRESENTATION value, Class<? extends MODEL> targetType, Locale locale) throws Converter.ConversionException
A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingconvertToPresentation(Object, Class, Locale)
and
convertToModel(Object, Class, Locale)
should return the original
value.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 convertedPRESENTATION convertToPresentation(MODEL value, Class<? extends PRESENTATION> targetType, Locale locale) throws Converter.ConversionException
A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingconvertToPresentation(Object, Class, Locale)
and
convertToModel(Object, Class, Locale)
should return the original
value.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 convertedClass<MODEL> getModelType()
convertToPresentation(Object, Class, Locale)
.Class<PRESENTATION> getPresentationType()
convertToModel(Object, Class, Locale)
.Copyright © 2019 Vaadin Ltd. All rights reserved.