Class ConverterUtil
java.lang.Object
com.vaadin.featurepack.data.util.converter.ConverterUtil
- All Implemented Interfaces:
Serializable
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanConverterHandle(com.vaadin.flow.data.converter.Converter<?, ?> converter, Class<?> presentationType, Class<?> modelType) Checks if the given converter can handle conversion between the given presentation and model type.static booleancanConverterPossiblyHandle(com.vaadin.flow.data.converter.Converter<?, ?> converter, Class<?> presentationType, Class<?> modelType) Checks if it possible that the given converter can handle conversion between the given presentation and model type somehow.static <PRESENTATIONTYPE,MODELTYPE>
PRESENTATIONTYPEconvertFromModel(com.vaadin.flow.component.Component field, MODELTYPE modelValue, Class<? extends PRESENTATIONTYPE> presentationType, com.vaadin.flow.data.converter.Converter<PRESENTATIONTYPE, MODELTYPE> converter) Convert the given value from the data source type to the UI type.static <MODELTYPE,PRESENTATIONTYPE>
MODELTYPEconvertToModel(com.vaadin.flow.component.Component field, PRESENTATIONTYPE presentationValue, Class<MODELTYPE> modelType, com.vaadin.flow.data.converter.Converter<PRESENTATIONTYPE, MODELTYPE> converter) Convert the given value from the presentation (UI) type to model (data source) type.static <PRESENTATIONTYPE,MODELTYPE>
Converter<PRESENTATIONTYPE, MODELTYPE> getConverter(Class<PRESENTATIONTYPE> presentationType, Class<MODELTYPE> modelType) Finds a converter that can convert from the given presentation type to the given model type and back.
-
Constructor Details
-
ConverterUtil
public ConverterUtil()
-
-
Method Details
-
getConverter
public static <PRESENTATIONTYPE,MODELTYPE> Converter<PRESENTATIONTYPE,MODELTYPE> getConverter(Class<PRESENTATIONTYPE> presentationType, Class<MODELTYPE> modelType) Finds a converter that can convert from the given presentation type to the given model type and back. Uses the given application to find aConverterFactoryor, if application is null, uses theVaadinSession.getCurrent().- Type Parameters:
PRESENTATIONTYPE- the presentation typeMODELTYPE- the model type- Parameters:
presentationType- the presentation typemodelType- the model typesession- the session to use to find a ConverterFactory or null to use the current session- Returns:
- a Converter capable of converting between the given types or null if no converter was found
-
convertFromModel
public static <PRESENTATIONTYPE,MODELTYPE> PRESENTATIONTYPE convertFromModel(com.vaadin.flow.component.Component field, MODELTYPE modelValue, Class<? extends PRESENTATIONTYPE> presentationType, com.vaadin.flow.data.converter.Converter<PRESENTATIONTYPE, MODELTYPE> converter) throws ConversionExceptionConvert the given value from the data source type to the UI type.- Type Parameters:
PRESENTATIONTYPE- the presentation typeMODELTYPE- the model type- Parameters:
modelValue- the model value to convertpresentationType- the type of the presentation valueconverter- the converter to uselocale- the locale to use for conversion- Returns:
- the converted value, compatible with the presentation type, or the original value if its type is compatible and no converter is set.
- Throws:
ConversionException- if there was a problem converting the value
-
convertToModel
public static <MODELTYPE,PRESENTATIONTYPE> MODELTYPE convertToModel(com.vaadin.flow.component.Component field, PRESENTATIONTYPE presentationValue, Class<MODELTYPE> modelType, com.vaadin.flow.data.converter.Converter<PRESENTATIONTYPE, MODELTYPE> converter) throws ConversionExceptionConvert the given value from the presentation (UI) type to model (data source) type.- Type Parameters:
MODELTYPE- the model typePRESENTATIONTYPE- the presentation type- Parameters:
presentationValue- the presentation value to convertmodelType- the type of the modelconverter- the converter to uselocale- the locale to use for conversion- Returns:
- the converted value, compatible with the model type, or the original value if its type is compatible and no converter is set.
-
canConverterHandle
public static boolean canConverterHandle(com.vaadin.flow.data.converter.Converter<?, ?> converter, Class<?> presentationType, Class<?> modelType) Checks if the given converter can handle conversion between the given presentation and model type. Does strict type checking and only returns true if the converter claims it can handle exactly the given types.- Parameters:
converter- The converter to check. If this is null the result is always false.presentationType- The presentation typemodelType- The model type- Returns:
- true if the converter supports conversion between the given presentation and model type, false otherwise
- See Also:
-
canConverterPossiblyHandle
public static boolean canConverterPossiblyHandle(com.vaadin.flow.data.converter.Converter<?, ?> converter, Class<?> presentationType, Class<?> modelType) Checks if it possible that the given converter can handle conversion between the given presentation and model type somehow.- Parameters:
converter- The converter to check. If this is null the result is always false.presentationType- The presentation typemodelType- The model type- Returns:
- true if the converter possibly support conversion between the given presentation and model type, false otherwise
-