diff options
3 files changed, 120 insertions, 2 deletions
diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java index 68f40f6cf3..8e98316d00 100644 --- a/server/src/com/vaadin/data/RpcDataProviderExtension.java +++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java @@ -637,6 +637,9 @@ public class RpcDataProviderExtension extends AbstractExtension { private KeyMapper<Object> columnKeys; + /* Has client been initialized */ + private boolean clientInitialized = false; + /** * Creates a new data provider using the given container. * @@ -687,6 +690,12 @@ public class RpcDataProviderExtension extends AbstractExtension { } + @Override + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); + clientInitialized = true; + } + private void pushRows(int firstRow, List<?> itemIds) { Collection<?> propertyIds = container.getContainerPropertyIds(); JsonArray rows = Json.createArray(); @@ -748,7 +757,9 @@ public class RpcDataProviderExtension extends AbstractExtension { */ private void insertRowData(int index, int count) { getState().containerSize += count; - rpc.insertRowData(index, count); + if (clientInitialized) { + rpc.insertRowData(index, count); + } activeRowHandler.insertRows(index, count); } @@ -765,7 +776,9 @@ public class RpcDataProviderExtension extends AbstractExtension { */ private void removeRowData(int firstIndex, int count) { getState().containerSize -= count; - rpc.removeRowData(firstIndex, count); + if (clientInitialized) { + rpc.removeRowData(firstIndex, count); + } for (int i = 0; i < count; i++) { Object itemId = keyMapper.itemIdAtIndex(firstIndex + i); diff --git a/uitest/src/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInit.java b/uitest/src/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInit.java new file mode 100644 index 0000000000..9a779a3cb0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInit.java @@ -0,0 +1,62 @@ +/* + * 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.Container.Indexed; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.components.grid.Grid; + +public class GridAddAndRemoveDataOnInit extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid gridAdd = new Grid(); + gridAdd.setHeight("240px"); + gridAdd.setWidth("140px"); + addComponent(gridAdd); + Indexed dataSource = gridAdd.getContainerDatasource(); + dataSource.addContainerProperty("foo", Integer.class, 0); + for (int i = 0; i < 10; ++i) { + Object id = dataSource.addItem(); + dataSource.getItem(id).getItemProperty("foo").setValue(i); + } + dataSource = new IndexedContainer(); + dataSource.addContainerProperty("bar", Integer.class, 0); + for (int i = 0; i < 10; ++i) { + Object id = dataSource.addItem(); + dataSource.getItem(id).getItemProperty("bar").setValue(i); + } + Grid gridRemove = new Grid(dataSource); + gridRemove.setHeight("150px"); + gridRemove.setWidth("140px"); + addComponent(gridRemove); + for (int i = 0; i < 5; ++i) { + dataSource.removeItem(dataSource.getIdByIndex(i)); + } + } + + @Override + protected String getTestDescription() { + return "Foo"; + } + + @Override + protected Integer getTicketNumber() { + return 13334; + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInitTest.java b/uitest/src/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInitTest.java new file mode 100644 index 0000000000..2f333698bf --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInitTest.java @@ -0,0 +1,43 @@ +/* + * 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 org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridAddAndRemoveDataOnInitTest extends MultiBrowserTest { + + @Test + public void verifyGridSizes() { + openTestURL(); + + GridElement gridAdd = $(GridElement.class).first(); + if (!gridAdd.isElementPresent(By.vaadin("#cell[9][1]")) + || gridAdd.isElementPresent(By.vaadin("#cell[10][1]"))) { + Assert.fail("Grid with added data contained incorrect rows"); + } + + GridElement gridRemove = $(GridElement.class).get(1); + if (!gridRemove.isElementPresent(By.vaadin("#cell[4][1]")) + || gridRemove.isElementPresent(By.vaadin("#cell[5][1]"))) { + Assert.fail("Grid with removed data contained incorrect rows"); + } + } + +} |