*/
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);
}
}
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;
}
+ @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
+ }
+ }
+
}