From: Henri Sara Date: Thu, 1 Dec 2011 09:05:53 +0000 (+0200) Subject: Handle fields with no data source in AbstractField.convertToDataSource() X-Git-Tag: 7.0.0.alpha1~230^2~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=32432d5e6efae65300819c2ae30d3ffedc193e6a;p=vaadin-framework.git Handle fields with no data source in AbstractField.convertToDataSource() --- diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index dbd6094300..73760d9247 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -766,30 +766,27 @@ public abstract class AbstractField 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 */