From 7aa9c79617009e6b33b710873ebdbddd9b91a463 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Fri, 4 May 2018 14:53:21 +0300 Subject: [PATCH] Fix Grid initial data when changing TabSheet Tab (#10872) --- .../data/provider/DataCommunicator.java | 5 ++++ .../tests/components/grid/GridInTabSheet.java | 27 ++++++++++++++++--- .../components/grid/GridInTabSheetTest.java | 17 ++++++++++++ 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 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 + extends com.vaadin.data.provider.DataCommunicator { + @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 extends com.vaadin.ui.Grid { + + public Grid() { + super(new DataCommunicator<>()); + } + } private AtomicInteger index = new AtomicInteger(0); @Override protected void setup(VaadinRequest request) { TabSheet sheet = new TabSheet(); + final Grid 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(); } -- 2.39.5