diff options
author | Henri Sara <hesara@vaadin.com> | 2015-11-06 10:54:10 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2016-08-08 09:44:24 +0000 |
commit | 06e0a6567b473fab0d1b3090eaa5a589613f8ae2 (patch) | |
tree | e28a770640dc60fa15cee8f141a29ea29ca944bd /server | |
parent | 07292fe8fb7b9d9cf94dd3a57cfab4e6e31bd639 (diff) | |
download | vaadin-framework-06e0a6567b473fab0d1b3090eaa5a589613f8ae2.tar.gz vaadin-framework-06e0a6567b473fab0d1b3090eaa5a589613f8ae2.zip |
Send ComboBox selection with RPC (#19929)
Send the selection from the client to the server with RPC.
Change-Id: I67e4e526f59550e83d9400729adf91e2b4bbb806
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/ComboBox.java | 40 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/components/ComboBoxValueChangeTest.java | 26 |
2 files changed, 34 insertions, 32 deletions
diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index e6b7b2be94..56fb649715 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -89,6 +89,20 @@ public class ComboBox extends AbstractSelect implements } } } + + @Override + public void setSelectedItem(String item) { + if (item == null) { + setValue(null, true); + } else { + final Object id = itemIdMapper.get(item); + if (id != null && id.equals(getNullSelectionItemId())) { + setValue(null, true); + } else { + setValue(id, true); + } + } + } }; FocusAndBlurServerRpcImpl focusBlurRpc = new FocusAndBlurServerRpcImpl(this) { @@ -267,8 +281,7 @@ public class ComboBox extends AbstractSelect implements boolean nullFilteredOut = isFilteringNeeded(); // null option is needed and not filtered out, even if not on - // current - // page + // current page boolean nullOptionVisible = needNullSelectOption && !nullFilteredOut; @@ -735,29 +748,6 @@ public class ComboBox extends AbstractSelect implements // Not calling super.changeVariables due the history of select // component hierarchy - // Selection change - if (variables.containsKey("selected")) { - final String[] ka = (String[]) variables.get("selected"); - - // Single select mode - if (ka.length == 0) { - - // Allows deselection only if the deselected item is visible - final Object current = getValue(); - final Collection<?> visible = getVisibleItemIds(); - if (visible != null && visible.contains(current)) { - setValue(null, true); - } - } else { - final Object id = itemIdMapper.get(ka[0]); - if (id != null && id.equals(getNullSelectionItemId())) { - setValue(null, true); - } else { - setValue(id, true); - } - } - } - String newFilter; if ((newFilter = (String) variables.get("filter")) != null) { // this is a filter request diff --git a/server/src/test/java/com/vaadin/tests/server/components/ComboBoxValueChangeTest.java b/server/src/test/java/com/vaadin/tests/server/components/ComboBoxValueChangeTest.java index 9d8901e129..887cc5fe48 100644 --- a/server/src/test/java/com/vaadin/tests/server/components/ComboBoxValueChangeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/components/ComboBoxValueChangeTest.java @@ -1,11 +1,11 @@ package com.vaadin.tests.server.components; -import java.util.HashMap; -import java.util.Map; - import org.junit.Before; import com.vaadin.legacy.ui.LegacyAbstractField; +import com.vaadin.server.ServerRpcManager; +import com.vaadin.server.ServerRpcMethodInvocation; +import com.vaadin.shared.ui.combobox.ComboBoxServerRpc; import com.vaadin.ui.ComboBox; /** @@ -19,16 +19,28 @@ public class ComboBoxValueChangeTest extends @Before public void setUp() { - ComboBox combo = new ComboBox(); + ComboBox combo = new ComboBox() { + @Override + public String getConnectorId() { + return "id"; + } + }; combo.addItem("myvalue"); super.setUp(combo); } @Override protected void setValue(LegacyAbstractField<Object> field) { - Map<String, Object> variables = new HashMap<String, Object>(); - variables.put("selected", new String[] { "myvalue" }); - ((ComboBox) field).changeVariables(field, variables); + ComboBox combo = (ComboBox) field; + ServerRpcMethodInvocation invocation = new ServerRpcMethodInvocation( + combo.getConnectorId(), ComboBoxServerRpc.class, + "setSelectedItem", 1); + invocation.setParameters(new Object[] { "myvalue" }); + try { + ServerRpcManager.applyInvocation(combo, invocation); + } catch (Exception e) { + throw new RuntimeException(e); + } } } |