]> source.dussan.org Git - vaadin-framework.git/commitdiff
Allow arbitrary serializable types as Renderer data type (#15410)
authorJohannes Dahlström <johannesd@vaadin.com>
Mon, 1 Jun 2015 14:09:04 +0000 (17:09 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 3 Jun 2015 13:53:22 +0000 (13:53 +0000)
Change-Id: If535c5603116be204e11936f9186ce3856b74b03

client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/RendererVisitor.java
uitest/src/com/vaadin/tests/components/grid/BeanRenderer.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java
uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java
uitest/src/com/vaadin/tests/serialization/EncodeResultDisplayTest.java
uitest/src/com/vaadin/tests/widgetset/client/EncoderResultDisplayConnector.java
uitest/src/com/vaadin/tests/widgetset/client/grid/PojoRendererConnector.java [new file with mode: 0644]

index 405925a920c47023ccc299daecbf3eb6d11c2819..fedc86fbf697a6a08c05a9ab6d36306ecd2ee00d 100644 (file)
@@ -48,6 +48,7 @@ import com.vaadin.client.ui.UnknownComponentConnector;
 import com.vaadin.shared.communication.ClientRpc;
 import com.vaadin.shared.communication.ServerRpc;
 import com.vaadin.shared.ui.Connect;
+
 import elemental.json.JsonValue;
 
 public class ConnectorBundle {
@@ -579,7 +580,7 @@ public class ConnectorBundle {
         frameworkHandledTypes.add(Set.class);
         frameworkHandledTypes.add(Byte.class);
         frameworkHandledTypes.add(Character.class);
-
+        frameworkHandledTypes.add(Void.class);
     }
 
     private boolean serializationHandledByFramework(JType setterType) {
index b0b947e3bf55af30f5406adf1dcd788807c4f038..12e67988eb1c768ddb495f1baf9e75f8ff1bd09a 100644 (file)
@@ -80,6 +80,8 @@ public class RendererVisitor extends TypeVisitor {
         JType presentationType = getPresentationType(type, logger);
         bundle.setPresentationType(type, presentationType);
 
+        bundle.setNeedsSerialize(presentationType);
+
         logger.log(Type.DEBUG, "Presentation type of " + type + " is "
                 + presentationType);
     }
diff --git a/uitest/src/com/vaadin/tests/components/grid/BeanRenderer.java b/uitest/src/com/vaadin/tests/components/grid/BeanRenderer.java
new file mode 100644 (file)
index 0000000..3e25f45
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.tests.widgetset.client.SimpleTestBean;
+import com.vaadin.ui.Grid.AbstractRenderer;
+
+public class BeanRenderer extends AbstractRenderer<SimpleTestBean> {
+    public BeanRenderer() {
+        super(SimpleTestBean.class, "");
+    }
+}
index f7d14bbff613a797d08d6955e6d8a3377ee641fa..171d3f2a5ed08a581b33b9eaa7461c410615d47c 100644 (file)
@@ -22,6 +22,7 @@ import com.vaadin.data.util.IndexedContainer;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.tests.components.AbstractTestUI;
 import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.tests.widgetset.client.SimpleTestBean;
 import com.vaadin.ui.Grid;
 import com.vaadin.ui.Grid.SelectionMode;
 import com.vaadin.ui.Label;
@@ -31,6 +32,7 @@ public class CustomRenderer extends AbstractTestUI {
 
     private static final Object INT_ARRAY_PROPERTY = "int array";
     private static final Object VOID_PROPERTY = "void";
+    private static final Object BEAN_PROPERTY = "pojo";
 
     static final Object ITEM_ID = "itemId1";
     static final String DEBUG_LABEL_ID = "debuglabel";
@@ -42,6 +44,8 @@ public class CustomRenderer extends AbstractTestUI {
         container.addContainerProperty(INT_ARRAY_PROPERTY, int[].class,
                 new int[] {});
         container.addContainerProperty(VOID_PROPERTY, Void.class, null);
+        container.addContainerProperty(BEAN_PROPERTY, SimpleTestBean.class,
+                null);
 
         Item item = container.addItem(ITEM_ID);
 
@@ -50,14 +54,25 @@ public class CustomRenderer extends AbstractTestUI {
                 .getItemProperty(INT_ARRAY_PROPERTY);
         propertyIntArray.setValue(new int[] { 1, 1, 2, 3, 5, 8, 13 });
 
+        @SuppressWarnings("unchecked")
+        Property<SimpleTestBean> propertyPojo = item
+                .getItemProperty(BEAN_PROPERTY);
+        SimpleTestBean bean = new SimpleTestBean();
+        bean.setValue(42);
+        propertyPojo.setValue(bean);
+
         Label debugLabel = new Label(INIT_DEBUG_LABEL_CAPTION);
         debugLabel.setId(DEBUG_LABEL_ID);
 
         Grid grid = new Grid(container);
+
         grid.getColumn(INT_ARRAY_PROPERTY).setRenderer(new IntArrayRenderer());
         grid.getColumn(VOID_PROPERTY).setRenderer(
                 new RowAwareRenderer(debugLabel));
+        grid.getColumn(BEAN_PROPERTY).setRenderer(new BeanRenderer());
+
         grid.setSelectionMode(SelectionMode.NONE);
+
         addComponent(grid);
         addComponent(debugLabel);
     }
index b17416df2aeb07b00dec27de2a83aad4464491a1..7d706ecd30e9c6211e89e53f571d748040a314a6 100644 (file)
@@ -52,6 +52,13 @@ public class CustomRendererTest extends MultiBrowserTest {
                 findDebugLabel().getText());
     }
 
+    @Test
+    public void testBeanRenderer() throws Exception {
+        openTestURL();
+
+        assertEquals("SimpleTestBean(42)", findGrid().getCell(0, 2).getText());
+    }
+
     private GridElement findGrid() {
         List<GridElement> elements = $(GridElement.class).all();
         return elements.get(0);
index dc69114f8eecc9559c312559deb2558b16bc051f..662a033745b243fc297bbb337ccfe9e51ba6dc5c 100644 (file)
@@ -27,6 +27,7 @@ public class EncodeResultDisplayTest extends SingleBrowserTest {
 
         int logRow = 0;
 
+        Assert.assertEquals("Void: null", getLogRow(logRow++));
         Assert.assertEquals("SimpleTestBean: {\"value\":5}",
                 getLogRow(logRow++));
         Assert.assertEquals("List: [\"Three\",\"Four\"]", getLogRow(logRow++));
index 8cc22de900c6e67cefc1304634d0ba45fff27a9f..f2e97104042853b41623236509b38fccdb047f51 100644 (file)
@@ -57,6 +57,9 @@ public class EncoderResultDisplayConnector extends AbstractExtensionConnector {
                 new Type(List.class.getName(), new Type[] { TypeData
                         .getType(String.class) }));
         reportEncode(new SimpleTestBean(5));
+
+        reportEncode(Void.class.getSimpleName(), null,
+                TypeData.getType(Void.class));
     }
 
     private void reportEncode(Object value) {
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/PojoRendererConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/PojoRendererConnector.java
new file mode 100644 (file)
index 0000000..04dd08d
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.widgetset.client.grid;
+
+import com.vaadin.client.connectors.AbstractRendererConnector;
+import com.vaadin.client.renderers.Renderer;
+import com.vaadin.client.widget.grid.RendererCellReference;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.tests.widgetset.client.SimpleTestBean;
+
+@Connect(com.vaadin.tests.components.grid.BeanRenderer.class)
+public class PojoRendererConnector extends
+        AbstractRendererConnector<SimpleTestBean> {
+
+    public static class BeanRenderer implements Renderer<SimpleTestBean> {
+        @Override
+        public void render(RendererCellReference cell, SimpleTestBean bean) {
+            cell.getElement().setInnerText(bean.toString());
+        }
+    }
+
+    @Override
+    public BeanRenderer getRenderer() {
+        return (BeanRenderer) super.getRenderer();
+    }
+}