]> source.dussan.org Git - vaadin-framework.git/commitdiff
Handle fields with no data source in AbstractField.convertToDataSource()
authorHenri Sara <hesara@vaadin.com>
Thu, 1 Dec 2011 09:05:53 +0000 (11:05 +0200)
committerHenri Sara <hesara@vaadin.com>
Thu, 1 Dec 2011 09:05:53 +0000 (11:05 +0200)
src/com/vaadin/ui/AbstractField.java

index dbd6094300a73053ecbd7a8f3e2a22d57b23f646..73760d9247fe9bbbe53773552892ac89f0fcbaf6 100644 (file)
@@ -766,30 +766,27 @@ public abstract class AbstractField<T> extends AbstractComponent implements
             // is no converter we can safely return null
             return null;
         }
-        if (getPropertyDataSource() != null) {
-            /*
-             * Data source is set
-             */
-            if (getPropertyDataSource().getType().isAssignableFrom(
-                    fieldValue.getClass())) {
-                return fieldValue;
-            } else {
-                throw new Converter.ConversionException(
-                        "Unable to convert value of type "
-                                + fieldValue.getClass().getName()
-                                + " to "
-                                + getPropertyDataSource().getType()
-                                + ". No value converter is set and the types are not compatible.");
 
-            }
+        // check that the value class is compatible with the data source type
+        // (if data source set) or field type
+        Class<?> type;
+        if (getPropertyDataSource() != null) {
+            type = getPropertyDataSource().getType();
+        } else {
+            type = getType();
         }
 
-        throw new Converter.ConversionException(
-                "Unable to convert value of type "
-                        + fieldValue.getClass().getName()
-                        + " to "
-                        + getType()
-                        + ". No value converter is set and the types are not compatible.");
+        if (type.isAssignableFrom(fieldValue.getClass())) {
+            return fieldValue;
+        } else {
+            throw new Converter.ConversionException(
+                    "Unable to convert value of type "
+                            + fieldValue.getClass().getName()
+                            + " to "
+                            + type.getName()
+                            + ". No value converter is set and the types are not compatible.");
+
+        }
     }
 
     /* Validation */