Old ValueChangeListeners are discarded and new ones created when an ItemSetChange occurs. This is done to reapply the listeners to possibly recreated Items. Change-Id: I9956af8950e241005574c597c49c5efb43afc1c7tags/7.6.0.rc1
@@ -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(); |
@@ -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"); | |||
} | |||
})); | |||
} | |||
} |
@@ -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()); | |||
} | |||
} |