Interface Converter<PRESENTATION,MODEL>
- Type Parameters:
PRESENTATION- The presentation type. Must be compatible with whatgetPresentationType()returns.MODEL- The model type. Must be compatible with whatgetModelType()returns.
- All Superinterfaces:
com.vaadin.flow.data.converter.Converter<PRESENTATION,,MODEL> Serializable
- All Known Implementing Classes:
AbstractStringToNumberConverter,DateToLongConverter,DateToSqlDateConverter,MultiSelectConverter,ReverseConverter,SingleSelectConverter,StringToBigDecimalConverter,StringToBigIntegerConverter,StringToBooleanConverter,StringToByteConverter,StringToCollectionConverter,StringToDateConverter,StringToDoubleConverter,StringToEnumConverter,StringToFloatConverter,StringToIntegerConverter,StringToLongConverter,StringToShortConverter
public interface Converter<PRESENTATION,MODEL>
extends Serializable, com.vaadin.flow.data.converter.Converter<PRESENTATION,MODEL>
Interface that implements conversion between a model and a presentation type.
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.
- Author:
- Vaadin Ltd.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classAn exception that signals that the value passed toconvertToPresentation(Object, Class, Locale)orconvertToModel(Object, Class, Locale)could not be converted. -
Method Summary
Modifier and TypeMethodDescriptiondefault com.vaadin.flow.data.binder.Result<MODEL> convertToModel(PRESENTATION value, com.vaadin.flow.data.binder.ValueContext context) convertToModel(PRESENTATION value, Class<? extends MODEL> targetType, Locale locale) Converts the given value from target type to source type.default PRESENTATIONconvertToPresentation(MODEL value, com.vaadin.flow.data.binder.ValueContext context) convertToPresentation(MODEL value, Class<? extends PRESENTATION> targetType, Locale locale) Converts the given value from source type to target type.The source type of the converter.The target type of the converter.Methods inherited from interface com.vaadin.flow.data.converter.Converter
chain
-
Method Details
-
convertToModel
default com.vaadin.flow.data.binder.Result<MODEL> convertToModel(PRESENTATION value, com.vaadin.flow.data.binder.ValueContext context) - Specified by:
convertToModelin interfacecom.vaadin.flow.data.converter.Converter<PRESENTATION,MODEL>
-
convertToPresentation
default PRESENTATION convertToPresentation(MODEL value, com.vaadin.flow.data.binder.ValueContext context) - Specified by:
convertToPresentationin interfacecom.vaadin.flow.data.converter.Converter<PRESENTATION,MODEL>
-
convertToModel
MODEL convertToModel(PRESENTATION value, Class<? extends MODEL> targetType, Locale locale) throws Converter.ConversionException Converts the given value from target type to source type.A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingconvertToPresentation(Object, Class, Locale)andconvertToModel(Object, Class, Locale)should return the original value.- Parameters:
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.- Returns:
- The converted value compatible with the source type
- Throws:
Converter.ConversionException- If the value could not be converted
-
convertToPresentation
PRESENTATION convertToPresentation(MODEL value, Class<? extends PRESENTATION> targetType, Locale locale) throws Converter.ConversionException Converts the given value from source type to target type.A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingconvertToPresentation(Object, Class, Locale)andconvertToModel(Object, Class, Locale)should return the original value.- Parameters:
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.- Returns:
- The converted value compatible with the source type
- Throws:
Converter.ConversionException- If the value could not be converted
-
getModelType
The source type of the converter. Values of this type can be passed toconvertToPresentation(Object, Class, Locale).- Returns:
- The source type
-
getPresentationType
Class<PRESENTATION> getPresentationType()The target type of the converter. Values of this type can be passed toconvertToModel(Object, Class, Locale).- Returns:
- The target type
-