diff options
author | Henri Sara <hesara@vaadin.com> | 2015-11-05 13:06:20 +0200 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2016-01-15 14:42:56 +0200 |
commit | 8985aef09fccc07b278a5bd082449e511bc5e511 (patch) | |
tree | 17a48918a48e0f124402caa190bea75621b9c5be | |
parent | 40e237abf0fb89a42dc5e0b6be673b84e6bea062 (diff) | |
download | vaadin-framework-8985aef09fccc07b278a5bd082449e511bc5e511.tar.gz vaadin-framework-8985aef09fccc07b278a5bd082449e511bc5e511.zip |
Create new items with RPC (#19929)
When the user creates a new item, send it with client to
server RPC.
Change-Id: I1b92073dc2791911e4916d17f749dc1f35e54bca
3 files changed, 21 insertions, 13 deletions
diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java index 449e519855..35e6fff04d 100644 --- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java +++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java @@ -378,8 +378,7 @@ public class ComboBoxConnector extends AbstractFieldConnector implements * user entered string value for the new item */ public void sendNewItem(String itemValue) { - getConnection().updateVariable(getConnectorId(), "newitem", itemValue, - immediate); + rpc.createNewItem(itemValue); } /** diff --git a/server/src/com/vaadin/ui/ComboBox.java b/server/src/com/vaadin/ui/ComboBox.java index c66aee0b34..189cf20aab 100644 --- a/server/src/com/vaadin/ui/ComboBox.java +++ b/server/src/com/vaadin/ui/ComboBox.java @@ -76,7 +76,18 @@ public class ComboBox extends AbstractSelect implements } private ComboBoxServerRpc rpc = new ComboBoxServerRpc() { - + @Override + public void createNewItem(String itemValue) { + if (isNewItemsAllowed()) { + // New option entered (and it is allowed) + if (itemValue != null && itemValue.length() > 0) { + getNewItemHandler().addNewItem(itemValue); + // rebuild list + filterstring = null; + prevfilterstring = null; + } + } + } }; /** @@ -733,15 +744,6 @@ public class ComboBox extends AbstractSelect implements filterstring = filterstring.toLowerCase(getLocale()); } requestRepaint(); - } else if (isNewItemsAllowed()) { - // New option entered (and it is allowed) - final String newitem = (String) variables.get("newitem"); - if (newitem != null && newitem.length() > 0) { - getNewItemHandler().addNewItem(newitem); - // rebuild list - filterstring = null; - prevfilterstring = null; - } } if (variables.containsKey(FocusEvent.EVENT_ID)) { diff --git a/shared/src/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java b/shared/src/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java index d140e7da6e..04d93c9062 100644 --- a/shared/src/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java +++ b/shared/src/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java @@ -23,5 +23,12 @@ import com.vaadin.shared.communication.ServerRpc; * @since */ public interface ComboBoxServerRpc extends ServerRpc { - + /** + * Create a new item in the combo box. This method can only be used when the + * ComboBox is configured to allow the creation of new items by the user. + * + * @param itemValue + * user entered string value for the new item + */ + public void createNewItem(String itemValue); } |