aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-06-25 15:48:27 +0300
committerArtur Signell <artur@vaadin.com>2012-06-25 15:51:37 +0300
commit4a997b3d5334d07185011f62e5508a88abc370fc (patch)
treef9d24da5e138e8a7e03636f32bdb9025c5616ec8 /src
parentfee6f306961ffff67809c33715c719075ba2c450 (diff)
downloadvaadin-framework-4a997b3d5334d07185011f62e5508a88abc370fc.tar.gz
vaadin-framework-4a997b3d5334d07185011f62e5508a88abc370fc.zip
Test for converter factory and related fixes (#8992)
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/data/util/converter/ConverterUtil.java7
-rw-r--r--src/com/vaadin/ui/AbstractField.java8
2 files changed, 10 insertions, 5 deletions
diff --git a/src/com/vaadin/data/util/converter/ConverterUtil.java b/src/com/vaadin/data/util/converter/ConverterUtil.java
index 239baf6b6d..206295b293 100644
--- a/src/com/vaadin/data/util/converter/ConverterUtil.java
+++ b/src/com/vaadin/data/util/converter/ConverterUtil.java
@@ -120,8 +120,11 @@ public class ConverterUtil implements Serializable {
return null;
}
- // check that the value class is compatible with the model type
- if (modelType.isAssignableFrom(presentationValue.getClass())) {
+ if (modelType == null) {
+ // No model type, return original value
+ return (MODELTYPE) presentationValue;
+ } else if (modelType.isAssignableFrom(presentationValue.getClass())) {
+ // presentation type directly compatible with model type
return modelType.cast(presentationValue);
} else {
throw new Converter.ConversionException(
diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java
index 21ca01f592..ce62fb43ed 100644
--- a/src/com/vaadin/ui/AbstractField.java
+++ b/src/com/vaadin/ui/AbstractField.java
@@ -591,7 +591,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
// Commits the value to datasource
committingValueToDataSource = true;
getPropertyDataSource().setValue(
- convertToDataSource(newFieldValue));
+ convertToModel(newFieldValue));
// The buffer is now unmodified
setModified(false);
@@ -792,13 +792,15 @@ public abstract class AbstractField<T> extends AbstractComponent implements
* if there is no converter and the type is not compatible with
* the data source type.
*/
- private Object convertToDataSource(T fieldValue)
+ private Object convertToModel(T fieldValue)
throws Converter.ConversionException {
try {
Class<?> modelType = null;
Property pd = getPropertyDataSource();
if (pd != null) {
modelType = pd.getType();
+ } else if (getConverter() != null) {
+ modelType = getConverter().getModelType();
}
return ConverterUtil.convertToModel(fieldValue,
(Class<Object>) modelType, getConverter(), getLocale());
@@ -836,7 +838,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
* @return The converted value that is compatible with the data source type
*/
public Object getConvertedValue() {
- return convertToDataSource(getFieldValue());
+ return convertToModel(getFieldValue());
}
/**