From 04650c56543a446008b8e379a56576472b8e093e Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Sat, 15 Oct 2016 23:02:15 +0300 Subject: [PATCH] Update client side selection state when changing selection model (#20370) Change-Id: I7fe8c160405a69140cac511c744d89a62c401cca --- server/src/main/java/com/vaadin/ui/Grid.java | 4 ++ .../server/GridSelectionTest.java | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index 3f61dcd88f..3bce7fcc39 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -5595,6 +5595,10 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, if (!SharedUtil.equals(oldSelection, newSelection)) { fireSelectionEvent(oldSelection, newSelection); } + + // selection is included in the row data, so the client needs to be + // updated + datasourceExtension.refreshCache(); } } diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java index bd2380ee45..a1dc542250 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java @@ -426,4 +426,44 @@ public class GridSelectionTest extends GridBasicFeaturesTest { private GridRowElement getRow(int i) { return getGridElement().getRow(i); } + + @Test + public void changeSelectionModelSingleToNone() throws Exception { + openTestURL(); + + setSelectionModelSingle(); + getGridElement().getCell(0, 0).click(); + assertTrue("row should become selected", getRow(0).isSelected()); + setSelectionModelNone(); + assertFalse("row should become deselected", getRow(0).isSelected()); + setSelectionModelSingle(); + assertFalse("row should still be deselected", getRow(0).isSelected()); + getGridElement().getCell(0, 0).click(); + assertTrue("row should become selected", getRow(0).isSelected()); + } + + @Test + public void changeSelectionModelMultiToNone() throws Exception { + openTestURL(); + + setSelectionModelMulti(); + getGridElement().getCell(0, 0).click(); + getGridElement().getCell(1, 0).click(); + getGridElement().getCell(2, 0).click(); + assertTrue("row should become selected", getRow(0).isSelected()); + assertTrue("row should become selected", getRow(1).isSelected()); + assertTrue("row should become selected", getRow(2).isSelected()); + + setSelectionModelNone(); + assertFalse("row should become deselected", getRow(0).isSelected()); + assertFalse("row should become deselected", getRow(1).isSelected()); + assertFalse("row should become deselected", getRow(2).isSelected()); + setSelectionModelMulti(); + assertFalse("row should still be deselected", getRow(0).isSelected()); + assertFalse("row should still be deselected", getRow(1).isSelected()); + assertFalse("row should still be deselected", getRow(2).isSelected()); + + getGridElement().getCell(0, 0).click(); + assertTrue("row should become selected", getRow(0).isSelected()); + } } -- 2.39.5