]> source.dussan.org Git - vaadin-framework.git/commitdiff
Allow null Components in ComponentRenderer (#9692) 8.1.0.rc2
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>
Wed, 19 Jul 2017 06:34:05 +0000 (09:34 +0300)
committerHenri Sara <henri.sara@gmail.com>
Wed, 19 Jul 2017 06:34:05 +0000 (09:34 +0300)
client/src/main/java/com/vaadin/client/connectors/grid/ComponentRendererConnector.java
server/src/main/java/com/vaadin/ui/renderers/ComponentRenderer.java
uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java
uitest/src/test/java/com/vaadin/tests/components/grid/GridComponentsTest.java

index c0944375386fcf11ab3505c9018b506f458a9391..6315f119cc844e380fc7293ebef23682699c0fbb 100644 (file)
@@ -51,9 +51,13 @@ public class ComponentRendererConnector
             @Override
             public void render(RendererCellReference cell, String connectorId,
                     SimplePanel widget) {
-                ComponentConnector connector = (ComponentConnector) ConnectorMap
-                        .get(getConnection()).getConnector(connectorId);
-                widget.setWidget(connector.getWidget());
+                if (connectorId != null) {
+                    ComponentConnector connector = (ComponentConnector) ConnectorMap
+                            .get(getConnection()).getConnector(connectorId);
+                    widget.setWidget(connector.getWidget());
+                } else if (widget.getWidget() != null) {
+                    widget.remove(widget.getWidget());
+                }
             }
         };
     }
index f5dd507cffa7f0549383c9e6a96f0f5d945bb3d0..0f8ca4401d39648cb082afad427ae2bb00a0bf10 100644 (file)
@@ -38,10 +38,11 @@ import elemental.json.JsonValue;
  * instances.
  * <p>
  * Example of how to add a {@link Label} component to {@link Grid}:
+ * 
  * <pre>
  * Grid<Person> grid;
- * grid.addColumn(person -> new Label(person.getFullName()), 
- *     new ComponentRenderer()).setCaption("Full Name");
+ * grid.addColumn(person -> new Label(person.getFullName()),
+ *         new ComponentRenderer()).setCaption("Full Name");
  * </pre>
  *
  * @author Vaadin Ltd
@@ -59,7 +60,7 @@ public class ComponentRenderer extends AbstractRenderer<Object, Component> {
 
     @Override
     public JsonValue encode(Component value) {
-        return Json.create(value.getConnectorId());
+        return value != null ? Json.create(value.getConnectorId()) : null;
     }
 
     @Override
index 6398ef105504a4d74bd28bfbc1b32670c41c2cc8..e1bf0f354a8fe78a094a34a260ef432d0a1850dd 100644 (file)
@@ -45,6 +45,9 @@ public class GridComponents extends AbstractTestUIWithLog {
             return textField;
         }).setId("textField").setCaption("TextField");
         grid.addColumn(string -> {
+            if (string.contains("30")) {
+                return null;
+            }
             Button button = new Button("Click Me!",
                     e -> Notification.show(
                             "Clicked button on row for: " + string,
index 295f06e4ceff5f5b2837005b3db3f17335746d0c..70966b373ef369146f6c20a65fd36d9f9c6cc2d7 100644 (file)
@@ -1,5 +1,8 @@
 package com.vaadin.tests.components.grid;
 
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
 import org.junit.Assert;
 import org.junit.Test;
 import org.openqa.selenium.WebElement;
@@ -98,6 +101,13 @@ public class GridComponentsTest extends MultiBrowserTest {
         assertRowExists(999, "Row 999");
     }
 
+    @Test
+    public void testRow30() {
+        openTestURL();
+        Stream.of(30, 130, 230, 330).forEach(this::assertNoButton);
+        IntStream.range(300, 310).forEach(this::assertNoButton);
+    }
+
     @Test
     public void testHeaders() {
         openTestURL();
@@ -118,4 +128,10 @@ public class GridComponentsTest extends MultiBrowserTest {
                 $(NotificationElement.class).first().getText()
                         .contains(string));
     }
+
+    private void assertNoButton(int i) {
+        GridRowElement row = $(GridElement.class).first().getRow(i);
+        Assert.assertFalse("Row " + i + " should not have a button",
+                row.getCell(2).isElementPresent(ButtonElement.class));
+    }
 }