summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java11
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridItemSetChange.java69
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridItemSetChangeTest.java48
3 files changed, 128 insertions, 0 deletions
diff --git a/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java b/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java
index 55b486d4b6..1b78ca4518 100644
--- a/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java
+++ b/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java
@@ -137,6 +137,10 @@ public class RpcDataProviderExtension extends AbstractExtension {
@Override
public void destroyData(Object itemId) {
keyMapper.remove(itemId);
+ removeListener(itemId);
+ }
+
+ private void removeListener(Object itemId) {
GridValueChangeListener removed = activeItemMap.remove(itemId);
if (removed != null) {
@@ -239,6 +243,13 @@ public class RpcDataProviderExtension extends AbstractExtension {
}
else {
+ // Remove obsolete value change listeners.
+ Set<Object> keySet = new HashSet<Object>(
+ activeItemHandler.activeItemMap.keySet());
+ for (Object itemId : keySet) {
+ activeItemHandler.removeListener(itemId);
+ }
+
/* Mark as dirty to push changes in beforeClientResponse */
bareItemSetTriggeredSizeChange = true;
markAsDirty();
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridItemSetChange.java b/uitest/src/com/vaadin/tests/components/grid/GridItemSetChange.java
new file mode 100644
index 0000000000..4632810561
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridItemSetChange.java
@@ -0,0 +1,69 @@
+/*
+ * 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.data.util.BeanItemContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.util.Person;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Grid;
+
+public class GridItemSetChange extends AbstractTestUI {
+
+ public static class SneakyBeanContainer extends BeanItemContainer<Person> {
+
+ private Person p = new Person("Foo", "Bar", "", "", "", 0, "");
+
+ public SneakyBeanContainer() throws IllegalArgumentException {
+ super(Person.class);
+ addItem(p);
+ }
+
+ public void reset() {
+ internalRemoveAllItems();
+ p.setLastName("Baz");
+ internalAddItemAtEnd(p, createBeanItem(p), false);
+ fireItemSetChange();
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final SneakyBeanContainer c = new SneakyBeanContainer();
+ Grid g = new Grid(c);
+ g.setColumns("firstName", "lastName");
+ addComponent(g);
+ addComponent(new Button("Reset", new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ c.reset();
+ }
+ }));
+ addComponent(new Button("Modify", new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ c.getItem(c.firstItemId()).getItemProperty("lastName")
+ .setValue("Spam");
+ }
+ }));
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridItemSetChangeTest.java b/uitest/src/com/vaadin/tests/components/grid/GridItemSetChangeTest.java
new file mode 100644
index 0000000000..dca1d71cb5
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridItemSetChangeTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class GridItemSetChangeTest extends SingleBrowserTest {
+
+ @Test
+ public void testValueChangeListenersWorkAfterItemSetChange() {
+ openTestURL();
+
+ GridElement grid = $(GridElement.class).first();
+ assertEquals("Last name initially wrong", "Bar", grid.getCell(0, 1)
+ .getText());
+
+ $(ButtonElement.class).caption("Modify").first().click();
+ assertEquals("Last name was not updated", "Spam", grid.getCell(0, 1)
+ .getText());
+
+ $(ButtonElement.class).caption("Reset").first().click();
+ assertEquals("Last name was not updated on reset", "Baz",
+ grid.getCell(0, 1).getText());
+
+ $(ButtonElement.class).caption("Modify").first().click();
+ assertEquals("Last name was not updated after reset modification",
+ "Spam", grid.getCell(0, 1).getText());
+ }
+}