From 0630b9f33e30f7194c06fc4f7b123a3b88c62d65 Mon Sep 17 00:00:00 2001 From: Olli Tietäväinen Date: Fri, 12 Jul 2019 10:44:55 +0300 Subject: 11642 refresh pagelength 0 combobox items after dataprovider update (#11653) * Fixes #11642. ComboBox with pageLength 0 should be updated if DataProvider changes * added comments, fixed imports --- server/src/main/java/com/vaadin/ui/ComboBox.java | 31 ++++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index c9622e1fd8..b9511450a5 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -28,17 +28,19 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Stream; -import org.jsoup.nodes.Element; - -import com.vaadin.data.HasFilterableDataProvider; -import com.vaadin.data.HasValue; -import com.vaadin.data.ValueProvider; import com.vaadin.data.provider.CallbackDataProvider; +import com.vaadin.data.provider.DataChangeEvent; import com.vaadin.data.provider.DataCommunicator; import com.vaadin.data.provider.DataGenerator; import com.vaadin.data.provider.DataKeyMapper; import com.vaadin.data.provider.DataProvider; +import com.vaadin.data.provider.InMemoryDataProvider; import com.vaadin.data.provider.ListDataProvider; +import org.jsoup.nodes.Element; + +import com.vaadin.data.HasFilterableDataProvider; +import com.vaadin.data.HasValue; +import com.vaadin.data.ValueProvider; import com.vaadin.event.FieldEvents; import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; @@ -219,6 +221,11 @@ public class ComboBox extends AbstractSingleSelect getState().currentFilterText = filterText; filterSlot.accept(filterText); } + + @Override + public void resetForceDataSourceUpdate() { + getState().forceDataSourceUpdate = false; + } }; /** @@ -962,6 +969,20 @@ public class ComboBox extends AbstractSingleSelect filterSlot = filter -> providerFilterSlot .accept(convertOrNull.apply(filter)); + + // This workaround is done to fix issue #11642 for unpaged comboboxes. + // Data sources for on the client need to be updated after data provider + // refreshAll so that serverside selection works even before the dropdown + // is opened. Only done for in-memory data providers for performance + // reasons. + if (dataProvider instanceof InMemoryDataProvider) { + dataProvider.addDataProviderListener(event -> { + if ((!(event instanceof DataChangeEvent.DataRefreshEvent)) + && (getPageLength() == 0)) { + getState().forceDataSourceUpdate = true; + } + }); + } } /** -- cgit v1.2.3