@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());
+ }
}
};
}
* 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
@Override
public JsonValue encode(Component value) {
- return Json.create(value.getConnectorId());
+ return value != null ? Json.create(value.getConnectorId()) : null;
}
@Override
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,
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;
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();
$(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));
+ }
}