diff options
-rw-r--r-- | server/src/main/java/com/vaadin/ui/ComboBox.java | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index 5d4a3f4f54..0a5a36c856 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -186,24 +186,22 @@ public class ComboBox<T> extends AbstractSingleSelect<T> @Override public void createNewItem(String itemValue) { // New option entered + boolean added = false; if (itemValue != null && !itemValue.isEmpty()) { if (getNewItemProvider() != null) { Optional<T> item = getNewItemProvider().apply(itemValue); - if (!item.isPresent()) { - // ensure the client resets the value to previous - // selection - getRpcProxy(ComboBoxClientRpc.class) - .newItemNotAdded(itemValue); - } + added = item.isPresent(); } else if (getNewItemHandler() != null) { getNewItemHandler().accept(itemValue); - } else { - // selection handling is needed at the client even if - // NewItemHandler is missing - getRpcProxy(ComboBoxClientRpc.class) - .newItemNotAdded(itemValue); + // Up to the user to tell if no item was added. + added = true; } } + + if (!added) { + // New item was not handled. + getRpcProxy(ComboBoxClientRpc.class).newItemNotAdded(itemValue); + } } @Override |