]> source.dussan.org Git - vaadin-framework.git/commitdiff
Render Object.toString() when no converter is set (#15417)
authorArtur Signell <artur@vaadin.com>
Thu, 5 Feb 2015 09:20:38 +0000 (11:20 +0200)
committerLeif Åstrand <leif@vaadin.com>
Thu, 5 Feb 2015 12:51:57 +0000 (12:51 +0000)
Change-Id: I8a00857d5829cd01ceb98c4264029f62e45e7073

server/src/com/vaadin/data/RpcDataProviderExtension.java
server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java

index d4e40ee915476b8ca44d652f15b01179d19ec2ee..630336816e32cf814e45e77400841ab07fa00676 100644 (file)
@@ -25,7 +25,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import com.google.gwt.thirdparty.guava.common.collect.BiMap;
@@ -40,7 +39,6 @@ import com.vaadin.data.Property.ValueChangeEvent;
 import com.vaadin.data.Property.ValueChangeListener;
 import com.vaadin.data.Property.ValueChangeNotifier;
 import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.Converter.ConversionException;
 import com.vaadin.server.AbstractExtension;
 import com.vaadin.server.ClientConnector;
 import com.vaadin.server.KeyMapper;
@@ -1060,20 +1058,19 @@ public class RpcDataProviderExtension extends AbstractExtension {
             try {
                 presentationValue = presentationType.cast(modelValue);
             } catch (ClassCastException e) {
-                ConversionException ee = new Converter.ConversionException(
-                        "Unable to convert value of type "
-                                + modelValue.getClass().getName()
-                                + " to presentation type "
-                                + presentationType.getName()
-                                + ". No converter is set and the types are not compatible.");
                 if (presentationType == String.class) {
-                    // We don't want to throw an exception for the default cause
-                    // when one column can't be rendered. Just log the exception
-                    // and let the column be empty
-                    presentationValue = (T) "";
-                    getLogger().log(Level.SEVERE, ee.getMessage(), ee);
+                    // If there is no converter, just fallback to using
+                    // toString().
+                    // modelValue can't be null as Class.cast(null) will always
+                    // succeed
+                    presentationValue = (T) modelValue.toString();
                 } else {
-                    throw ee;
+                    throw new Converter.ConversionException(
+                            "Unable to convert value of type "
+                                    + modelValue.getClass().getName()
+                                    + " to presentation type "
+                                    + presentationType.getName()
+                                    + ". No converter is set and the types are not compatible.");
                 }
             }
         } else {
index 464d409543f6c8014492821f2b2f66f46a161ed4..f6a766bd0715829e1239c6d686143d10f33eeea5 100644 (file)
@@ -44,6 +44,11 @@ public class RendererTest {
 
     private static class TestBean {
         int i = 42;
+
+        @Override
+        public String toString() {
+            return "TestBean [" + i + "]";
+        }
     }
 
     private static class ExtendedBean extends TestBean {
@@ -177,7 +182,7 @@ public class RendererTest {
 
     @Test
     public void testEncodingWithoutConverter() throws Exception {
-        assertEquals("", render(baz, new TestBean()).asString());
+        assertEquals("TestBean [42]", render(baz, new TestBean()).asString());
     }
 
     @Test