aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/ui/AbstractField.java17
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java20
2 files changed, 28 insertions, 9 deletions
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java
index 59f730f275..53301f093a 100644
--- a/server/src/com/vaadin/ui/AbstractField.java
+++ b/server/src/com/vaadin/ui/AbstractField.java
@@ -687,19 +687,18 @@ public abstract class AbstractField<T> extends AbstractComponent implements
*/
private Object convertToModel(T fieldValue)
throws Converter.ConversionException {
+ Class<?> modelType = null;
+ Property pd = getPropertyDataSource();
+ if (pd != null) {
+ modelType = pd.getType();
+ } else if (getConverter() != null) {
+ modelType = getConverter().getModelType();
+ }
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());
} catch (ConversionException e) {
- throw new ConversionException(
- getConversionError(converter.getModelType()), e);
+ throw new ConversionException(getConversionError(modelType), e);
}
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java
index 73f6063fdd..83224861b6 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java
@@ -2,10 +2,15 @@ package com.vaadin.tests.server.component.abstractfield;
import java.util.Locale;
+import junit.framework.Assert;
import junit.framework.TestCase;
+import org.junit.Test;
+
import com.vaadin.data.util.MethodProperty;
+import com.vaadin.data.util.ObjectProperty;
import com.vaadin.data.util.converter.Converter;
+import com.vaadin.data.util.converter.Converter.ConversionException;
import com.vaadin.data.util.converter.StringToIntegerConverter;
import com.vaadin.server.VaadinServiceSession;
import com.vaadin.tests.data.bean.Address;
@@ -179,4 +184,19 @@ public class AbstractFieldValueConversions extends TestCase {
}
+ @Test
+ public void testNullConverter() {
+ TextField tf = new TextField("foo");
+ tf.setPropertyDataSource(new ObjectProperty<Integer>(12));
+ tf.setConverter((Converter) null);
+ try {
+ Object v = tf.getConvertedValue();
+ System.out.println(v);
+ Assert.fail("Trying to convert String -> Integer should fail when there is no converter");
+ } catch (ConversionException e) {
+ // ok, should happen when there is no converter but conversion is
+ // needed
+ }
+ }
+
}