summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2018-07-19 13:50:33 +0300
committerIlia Motornyi <elmot@vaadin.com>2018-07-19 13:50:33 +0300
commit10278f866e461c687f6d593ac8ec02c65e150da8 (patch)
tree31177a50c4189bd86338c5a6a0854f71ff2602ad /server
parent5ef55253e5f26bdebf9e6ab6e14640d1f3002727 (diff)
downloadvaadin-framework-10278f866e461c687f6d593ac8ec02c65e150da8.tar.gz
vaadin-framework-10278f866e461c687f6d593ac8ec02c65e150da8.zip
Fix DataCommunicator not sending data on filter updates (#11068)
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/data/provider/DataCommunicator.java3
-rw-r--r--server/src/test/java/com/vaadin/data/provider/BackendDataProviderTest.java1
-rw-r--r--server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java44
3 files changed, 47 insertions, 1 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 f5d2d087e6..5a99cacfb9 100644
--- a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java
+++ b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java
@@ -677,6 +677,9 @@ public class DataCommunicator<T> extends AbstractExtension {
if (!Objects.equals(this.filter, filter)) {
setFilter(filter);
reset();
+
+ // Make sure filter change causes data to be sent again.
+ markAsDirty();
}
};
}
diff --git a/server/src/test/java/com/vaadin/data/provider/BackendDataProviderTest.java b/server/src/test/java/com/vaadin/data/provider/BackendDataProviderTest.java
index da45054325..256a5de352 100644
--- a/server/src/test/java/com/vaadin/data/provider/BackendDataProviderTest.java
+++ b/server/src/test/java/com/vaadin/data/provider/BackendDataProviderTest.java
@@ -47,7 +47,6 @@ public class BackendDataProviderTest extends
}
List<StrBean> list = stream.skip(query.getOffset())
.limit(query.getLimit()).collect(Collectors.toList());
- list.forEach(s -> System.err.println(s));
return list.stream();
}, query -> (int) data.stream()
.filter(t -> query.getFilter().orElse(s -> true).test(t))
diff --git a/server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java b/server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java
index 5114390dd8..d07fa27eb0 100644
--- a/server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java
+++ b/server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java
@@ -11,6 +11,8 @@ import org.junit.Test;
import org.mockito.Mockito;
import com.vaadin.server.MockVaadinSession;
+import com.vaadin.server.SerializableConsumer;
+import com.vaadin.server.SerializablePredicate;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinService;
import com.vaadin.server.VaadinSession;
@@ -207,4 +209,46 @@ public class DataCommunicatorTest {
assertFalse("Stalled object in KeyMapper",
communicator.getKeyMapper().has(TEST_OBJECT));
}
+
+ @Test
+ public void testFilteringLock() {
+ session.lock();
+ UI ui = new TestUI(session);
+ TestDataCommunicator communicator = new TestDataCommunicator();
+ communicator.extend(ui);
+
+ ListDataProvider<Object> dataProvider = DataProvider.ofItems("one",
+ "two", "three");
+ SerializableConsumer<SerializablePredicate<Object>> filterSlot = communicator
+ .setDataProvider(dataProvider, null);
+ communicator.beforeClientResponse(true);
+
+ // Mock empty request
+ filterSlot.accept(t -> String.valueOf(t).contains("a"));
+ communicator.beforeClientResponse(false);
+
+ // Assume client clears up the filter
+ filterSlot.accept(t -> String.valueOf(t).contains(""));
+ communicator.beforeClientResponse(false);
+
+ // And in the next request sets a non-matching filter
+ // and has the data request for previous change
+ communicator.onRequestRows(0, 3, 0, 0);
+ filterSlot.accept(t -> String.valueOf(t).contains("a"));
+ communicator.beforeClientResponse(false);
+
+ // Mark communicator clean
+ ui.getConnectorTracker().markClean(communicator);
+
+ assertTrue("Communicator should be marked for hard reset",
+ communicator.reset);
+ assertFalse("DataCommunicator should not be marked as dirty",
+ ui.getConnectorTracker().isDirty(communicator));
+
+ // Set a filter that gets results again.
+ filterSlot.accept(t -> String.valueOf(t).contains(""));
+
+ assertTrue("DataCommunicator should be marked as dirty",
+ ui.getConnectorTracker().isDirty(communicator));
+ }
}