summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/data/util
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-05-21 16:51:32 +0300
committerVaadin Code Review <review@vaadin.com>2013-05-22 13:50:40 +0000
commit6bf83a428aa747f6b46d1d4c4ad2e279971d14e7 (patch)
tree2120465ccf24b83acf01ba6c829c4fe59866b74b /server/src/com/vaadin/data/util
parent0b635061bb9b30e9f28d49fe9606eb3cab2fd3f1 (diff)
downloadvaadin-framework-6bf83a428aa747f6b46d1d4c4ad2e279971d14e7.tar.gz
vaadin-framework-6bf83a428aa747f6b46d1d4c4ad2e279971d14e7.zip
Modified the logic in setPropertyDatasource which determines if a new converter is needed (#11863)
The previous logic had two flaws * It allowed converter model type to be a sub type of the model type but not vice versa. Similarly for presentation type. * If the user has set a converter it should be used and not be replaced unless it is absolutely sure that it cannot in any possible way handle conversion (e.g. converter from integer to double cannot handle string to list conversion). If there is a slight chance that it can handle conversion, let it be and let the user set another converter when needed. Change-Id: I2e1c0b3aac90be63ddbc780195f8428398e28ada
Diffstat (limited to 'server/src/com/vaadin/data/util')
-rw-r--r--server/src/com/vaadin/data/util/converter/ConverterUtil.java50
1 files changed, 46 insertions, 4 deletions
diff --git a/server/src/com/vaadin/data/util/converter/ConverterUtil.java b/server/src/com/vaadin/data/util/converter/ConverterUtil.java
index 61d155bc9a..08d7363084 100644
--- a/server/src/com/vaadin/data/util/converter/ConverterUtil.java
+++ b/server/src/com/vaadin/data/util/converter/ConverterUtil.java
@@ -151,10 +151,14 @@ public class ConverterUtil implements Serializable {
/**
* Checks if the given converter can handle conversion between the given
- * presentation and model type
+ * presentation and model type. Does strict type checking and only returns
+ * true if the converter claims it can handle exactly the given types.
+ *
+ * @see #canConverterPossiblyHandle(Converter, Class, Class)
*
* @param converter
- * The converter to check
+ * The converter to check. If this is null the result is always
+ * false.
* @param presentationType
* The presentation type
* @param modelType
@@ -168,10 +172,48 @@ public class ConverterUtil implements Serializable {
return false;
}
- if (!modelType.isAssignableFrom(converter.getModelType())) {
+ if (modelType != converter.getModelType()) {
+ return false;
+ }
+ if (presentationType != converter.getPresentationType()) {
return false;
}
- if (!presentationType.isAssignableFrom(converter.getPresentationType())) {
+
+ return true;
+ }
+
+ /**
+ * Checks if it possible that the given converter can handle conversion
+ * between the given presentation and model type somehow.
+ *
+ * @param converter
+ * The converter to check. If this is null the result is always
+ * false.
+ * @param presentationType
+ * The presentation type
+ * @param modelType
+ * The model type
+ * @return true if the converter possibly support conversion between the
+ * given presentation and model type, false otherwise
+ */
+ public static boolean canConverterPossiblyHandle(Converter<?, ?> converter,
+ Class<?> presentationType, Class<?> modelType) {
+ if (converter == null) {
+ return false;
+ }
+ Class<?> converterModelType = converter.getModelType();
+
+ if (!modelType.isAssignableFrom(converterModelType)
+ && !converterModelType.isAssignableFrom(modelType)) {
+ // model types are not compatible in any way
+ return false;
+ }
+
+ Class<?> converterPresentationType = converter.getPresentationType();
+ if (!presentationType.isAssignableFrom(converterPresentationType)
+ && !converterPresentationType
+ .isAssignableFrom(presentationType)) {
+ // presentation types are not compatible in any way
return false;
}