From d3eb272d7be8ef8f2ceca1b9fc85f2adf5c564ea Mon Sep 17 00:00:00 2001 From: Sun Zhe <31067185+ZheSun88@users.noreply.github.com> Date: Wed, 24 Apr 2019 13:28:01 +0300 Subject: Reset Combobox internal state (#11412) issue in #11343 and #11385 is not reproducible on top this patch Three different bugs are involved in this fix: we bring the old fix(#11094) back and fixed the other related issues: 1) allow adding the same new item after dataProvider got reset, This is cause by the client side parameter `LastNewItemString`, it saves the value added before resetting. 2) clear the pending newItem eagerly, so that the same value will not be added again. --- server/src/main/java/com/vaadin/ui/ComboBox.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 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 a976782ecc..8fadca6c35 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -191,6 +191,15 @@ public class ComboBox extends AbstractSingleSelect if (getNewItemProvider() != null) { Optional item = getNewItemProvider().apply(itemValue); added = item.isPresent(); + // Fixes issue https://github.com/vaadin/framework/issues/11343 + // Update the internal selection state immediately to avoid + // client side hanging. This is needed for cases that user + // interaction fires multi events (like adding and deleting) + // on a new item during the same round trip. + item.ifPresent(value -> { + setSelectedItem(value, true); + getDataCommunicator().reset(); + }); } else if (getNewItemHandler() != null) { getNewItemHandler().accept(itemValue); // Up to the user to tell if no item was added. @@ -446,7 +455,7 @@ public class ComboBox extends AbstractSingleSelect * @since 8.0 */ public void setDataProvider(CaptionFilter captionFilter, - ListDataProvider listDataProvider) { + ListDataProvider listDataProvider) { Objects.requireNonNull(listDataProvider, "List data provider cannot be null"); @@ -610,12 +619,11 @@ public class ComboBox extends AbstractSingleSelect *

* The empty string {@code ""} is the default empty selection caption. * + * @return the empty selection caption, not {@code null} * @see #setEmptySelectionAllowed(boolean) * @see #isEmptySelectionAllowed() * @see #setEmptySelectionCaption(String) * @see #isSelected(Object) - * - * @return the empty selection caption, not {@code null} * @since 8.0 */ public String getEmptySelectionCaption() { -- cgit v1.2.3