diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-05-04 14:53:21 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-05-16 07:43:56 +0300 |
commit | b6d5d0cac8a9ae2f99ef7fdc34d8e53353fcf84b (patch) | |
tree | 381e53277d0f9a374831713201b427080b06c0b5 | |
parent | b9f0aae9e493c015e107a88ef4a9d9f329edf3ab (diff) | |
download | vaadin-framework-b6d5d0cac8a9ae2f99ef7fdc34d8e53353fcf84b.tar.gz vaadin-framework-b6d5d0cac8a9ae2f99ef7fdc34d8e53353fcf84b.zip |
Fix Grid initial data when changing TabSheet Tab (#10872)
3 files changed, 46 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java index 99201965f1..574ed99045 100644 --- a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java +++ b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java @@ -220,6 +220,11 @@ public class DataCommunicator<T> extends AbstractExtension { public void attach() { super.attach(); attachDataProviderListener(); + + if (getPushRows().isEmpty()) { + // Make sure rows are pushed when component is attached. + setPushRows(Range.withLength(0, getMinPushSize())); + } } @Override diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInTabSheet.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInTabSheet.java index e04f25262e..e50aa9759b 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInTabSheet.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInTabSheet.java @@ -5,25 +5,46 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.IntStream; +import com.vaadin.annotations.Widgetset; import com.vaadin.data.ValueProvider; import com.vaadin.data.provider.DataProvider; import com.vaadin.data.provider.ListDataProvider; import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.Button; -import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.Label; import com.vaadin.ui.TabSheet; import com.vaadin.ui.renderers.NumberRenderer; -public class GridInTabSheet extends AbstractReindeerTestUI { +@Widgetset("com.vaadin.DefaultWidgetSet") +public class GridInTabSheet extends AbstractTestUIWithLog { + + public class DataCommunicator<T> + extends com.vaadin.data.provider.DataCommunicator<T> { + @Override + protected void onRequestRows(int firstRowIndex, int numberOfRows, + int firstCachedRowIndex, int cacheSize) { + log("RequestRows: [" + firstRowIndex + "," + numberOfRows + "," + + firstCachedRowIndex + "," + cacheSize + "]"); + super.onRequestRows(firstRowIndex, numberOfRows, + firstCachedRowIndex, cacheSize); + } + } + + public class Grid<T> extends com.vaadin.ui.Grid<T> { + + public Grid() { + super(new DataCommunicator<>()); + } + } private AtomicInteger index = new AtomicInteger(0); @Override protected void setup(VaadinRequest request) { TabSheet sheet = new TabSheet(); + final Grid<Integer> grid = new Grid<>(); grid.setSelectionMode(SelectionMode.MULTI); grid.addColumn(ValueProvider.identity(), new NumberRenderer()) diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInTabSheetTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInTabSheetTest.java index e20ec622c7..785bda8261 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInTabSheetTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInTabSheetTest.java @@ -2,6 +2,8 @@ package com.vaadin.tests.components.grid; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -68,6 +70,21 @@ public class GridInTabSheetTest extends MultiBrowserTest { assertNoNotification(); } + @Test + public void testNoDataRequestFromClientWhenSwitchingTab() { + setDebug(true); + openTestURL(); + + TabSheetElement tabsheet = $(TabSheetElement.class).first(); + tabsheet.openTab("Label"); + tabsheet.openTab("Grid"); + + getLogs().forEach(logText -> assertTrue( + "There should be no logged requests, was: " + logText, + logText.trim().isEmpty())); + assertNoNotification(); + } + private void removeGridRow() { $(ButtonElement.class).caption("Remove row from Grid").first().click(); } |