* on initialization, but not after that.
*/
private DataSource<T> dataSource;
+ private Registration changeHandler;
/**
* Currently available row range in DataSource.
selectionModel.reset();
- if (this.dataSource != null) {
- this.dataSource.addDataChangeHandler((DataChangeHandler) null);
+ if (changeHandler != null) {
+ changeHandler.remove();
+ changeHandler = null;
}
this.dataSource = dataSource;
- dataSource.addDataChangeHandler(new DataChangeHandler() {
+ changeHandler = dataSource.addDataChangeHandler(new DataChangeHandler() {
@Override
public void dataUpdated(int firstIndex, int numberOfItems) {
escalator.getBody().refreshRows(firstIndex, numberOfItems);
--- /dev/null
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.v7.data.util.IndexedContainer;
+import com.vaadin.v7.ui.Grid;
+
+@Widgetset("com.vaadin.v7.Vaadin7WidgetSet")
+public class GridRebindDataSourceV7 extends AbstractTestUI {
+ private Grid grid;
+ private IndexedContainer container = new IndexedContainer();
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ container.addContainerProperty("name", String.class, null);
+ container.addItem("test").getItemProperty("name").setValue("test");
+ grid = new Grid();
+ grid.setContainerDataSource(container);
+ grid.setEditorEnabled(true);
+ addComponent(grid);
+
+ Button button = new Button("Change container",
+ new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(Button.ClickEvent event) {
+ IndexedContainer container = new IndexedContainer();
+ container.addContainerProperty("age", Integer.class,
+ null);
+ container.addItem("first").getItemProperty("age")
+ .setValue(45);
+ grid.removeAllColumns();
+ grid.setContainerDataSource(container);
+ }
+ });
+ button.setId("changeContainer");
+ addComponent(button);
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Test;
+import org.openqa.selenium.By;
+
+public class GridRebindDataSourceV7Test extends MultiBrowserTest {
+
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+
+ setDebug(true);
+ openTestURL();
+ waitForElementPresent(By.className("v-grid"));
+ }
+
+ @Test
+ public void testNoNPE() {
+ findElement(By.id("changeContainer")).click();
+ assertNoErrorNotifications();
+ }
+}