]> source.dussan.org Git - vaadin-framework.git/commitdiff
Create new items with RPC (#19929)
authorHenri Sara <hesara@vaadin.com>
Thu, 5 Nov 2015 11:06:20 +0000 (13:06 +0200)
committerHenri Sara <hesara@vaadin.com>
Fri, 15 Jan 2016 12:42:56 +0000 (14:42 +0200)
When the user creates a new item, send it with client to
server RPC.

Change-Id: I1b92073dc2791911e4916d17f749dc1f35e54bca

client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
server/src/com/vaadin/ui/ComboBox.java
shared/src/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java

index 449e519855c59eb6479a8a9e9e1174b823a070a7..35e6fff04d6866b91290c6cfe03ccaa1463cad56 100644 (file)
@@ -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);
     }
 
     /**
index c66aee0b3402d1b64edd26ce68105fa57da91398..189cf20aab7369fecbd9c949c96ed4a31ebd42fe 100644 (file)
@@ -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)) {
index d140e7da6e35f89edf9060cb15e78d659ba16c8d..04d93c906262e061b1f3ec1aaa9479c7b3f74600 100644 (file)
@@ -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);
 }