aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2015-11-06 10:54:10 +0200
committerHenri Sara <hesara@vaadin.com>2016-01-15 14:42:56 +0200
commit733a33ab8dde7af788ff207d84e8cd8b1972cc1a (patch)
tree930a375dbe35a913fdcda2e553d834fa6dce4657
parentf2b9f4779defd22258cb2e0037bdfd10f4c348f4 (diff)
downloadvaadin-framework-733a33ab8dde7af788ff207d84e8cd8b1972cc1a.tar.gz
vaadin-framework-733a33ab8dde7af788ff207d84e8cd8b1972cc1a.zip
Send ComboBox selection with RPC (#19929)
Send the selection from the client to the server with RPC. Change-Id: Ic32d869c3dc2a8806f9c7cfd1f3db8263a5379a9
-rw-r--r--client/src/com/vaadin/client/ui/VFilterSelect.java2
-rw-r--r--client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java10
-rw-r--r--server/src/com/vaadin/ui/ComboBox.java40
-rw-r--r--server/tests/src/com/vaadin/tests/server/components/ComboBoxValueChangeTest.java26
-rw-r--r--shared/src/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java8
5 files changed, 47 insertions, 39 deletions
diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java
index 86ef67cde6..82c324e186 100644
--- a/client/src/com/vaadin/client/ui/VFilterSelect.java
+++ b/client/src/com/vaadin/client/ui/VFilterSelect.java
@@ -1631,7 +1631,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
if (!(newKey.equals(selectedOptionKey) || ("".equals(newKey) && selectedOptionKey == null))) {
selectedOptionKey = newKey;
- connector.sendSelection(new String[] { selectedOptionKey });
+ connector.sendSelection(selectedOptionKey);
afterUpdateClientVariables();
// currentPage = -1; // forget the page
diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
index 646f4b8bb6..3af86d324c 100644
--- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
+++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
@@ -396,10 +396,9 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
* @since
*/
public void requestFirstPage() {
+ sendSelection(null);
getConnection().updateVariable(getConnectorId(), "filter", "", false);
- getConnection().updateVariable(getConnectorId(), "page", 0, false);
- getConnection().updateVariable(getConnectorId(), "selected",
- new String[] {}, immediate);
+ getConnection().updateVariable(getConnectorId(), "page", 0, true);
}
/**
@@ -432,9 +431,8 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
* @param selection
* the current selection
*/
- public void sendSelection(String[] selection) {
- getConnection().updateVariable(getConnectorId(), "selected", selection,
- immediate);
+ public void sendSelection(String selection) {
+ rpc.setSelectedItem(selection);
}
/**
diff --git a/server/src/com/vaadin/ui/ComboBox.java b/server/src/com/vaadin/ui/ComboBox.java
index ecc181a0f7..271e273c46 100644
--- a/server/src/com/vaadin/ui/ComboBox.java
+++ b/server/src/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) {
@@ -253,8 +267,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;
@@ -721,29 +734,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/tests/src/com/vaadin/tests/server/components/ComboBoxValueChangeTest.java b/server/tests/src/com/vaadin/tests/server/components/ComboBoxValueChangeTest.java
index f3cc337657..3b87082398 100644
--- a/server/tests/src/com/vaadin/tests/server/components/ComboBoxValueChangeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/components/ComboBoxValueChangeTest.java
@@ -1,8 +1,8 @@
package com.vaadin.tests.server.components;
-import java.util.HashMap;
-import java.util.Map;
-
+import com.vaadin.server.ServerRpcManager;
+import com.vaadin.server.ServerRpcMethodInvocation;
+import com.vaadin.shared.ui.combobox.ComboBoxServerRpc;
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.ComboBox;
@@ -16,16 +16,28 @@ public class ComboBoxValueChangeTest extends
AbstractFieldValueChangeTestBase<Object> {
@Override
protected void setUp() throws Exception {
- ComboBox combo = new ComboBox();
+ ComboBox combo = new ComboBox() {
+ @Override
+ public String getConnectorId() {
+ return "id";
+ }
+ };
combo.addItem("myvalue");
super.setUp(combo);
}
@Override
protected void setValue(AbstractField<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);
+ }
}
}
diff --git a/shared/src/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java b/shared/src/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java
index 04d93c9062..38704b5169 100644
--- a/shared/src/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java
+++ b/shared/src/com/vaadin/shared/ui/combobox/ComboBoxServerRpc.java
@@ -31,4 +31,12 @@ public interface ComboBoxServerRpc extends ServerRpc {
* user entered string value for the new item
*/
public void createNewItem(String itemValue);
+
+ /**
+ * Set the current selection.
+ *
+ * @param item
+ * the id of a single item or null to deselect the current value
+ */
+ public void setSelectedItem(String item);
}