aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-05-06 18:04:06 +0300
committerVaadin Code Review <review@vaadin.com>2016-05-09 12:44:19 +0000
commitd3c617a77dcf6df7cf200f45430fb35b671121ac (patch)
treeb516cea88bc3b4458cdbd67f7a78ea34114946ee
parente5765f1e53b47354b5d0910fe0c19c008734ba53 (diff)
downloadvaadin-framework-d3c617a77dcf6df7cf200f45430fb35b671121ac.tar.gz
vaadin-framework-d3c617a77dcf6df7cf200f45430fb35b671121ac.zip
Fix null selection to work again (#19787)
Reverts the fix for #15181 Change-Id: I9ec45b1c9aad9788559d0de2b086bf5cf4af6b12
-rw-r--r--server/src/main/java/com/vaadin/server/KeyMapper.java14
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractSelect.java17
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectNull.java25
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectNullTest.java20
4 files changed, 69 insertions, 7 deletions
diff --git a/server/src/main/java/com/vaadin/server/KeyMapper.java b/server/src/main/java/com/vaadin/server/KeyMapper.java
index 0e4b7edc77..709c3e0c2d 100644
--- a/server/src/main/java/com/vaadin/server/KeyMapper.java
+++ b/server/src/main/java/com/vaadin/server/KeyMapper.java
@@ -93,4 +93,18 @@ public class KeyMapper<V> implements Serializable {
objectKeyMap.clear();
keyObjectMap.clear();
}
+
+ /**
+ * Checks if the given key is mapped to an object.
+ *
+ * @since
+ *
+ * @param key
+ * the key to check
+ * @return <code>true</code> if the key is currently mapped,
+ * <code>false</code> otherwise
+ */
+ public boolean containsKey(String key) {
+ return keyObjectMap.containsKey(key);
+ }
}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractSelect.java b/server/src/main/java/com/vaadin/ui/AbstractSelect.java
index 2714e0cbf5..882458c531 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractSelect.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractSelect.java
@@ -530,18 +530,21 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
setValue(null, true);
}
} else {
- final Object id = itemIdMapper
- .get(clientSideSelectedKeys[0]);
-
- if (id != null) {
- if (isNullSelectionAllowed()
+ String clientSelectedKey = clientSideSelectedKeys[0];
+ if ("null".equals(clientSelectedKey)
+ || itemIdMapper.containsKey(clientSelectedKey)) {
+ // Happens to work for nullselection
+ // (get ("null") -> null))
+ final Object id = itemIdMapper.get(clientSelectedKey);
+
+ if (!isNullSelectionAllowed() && id == null) {
+ markAsDirty();
+ } else if (id != null
&& id.equals(getNullSelectionItemId())) {
setValue(null, true);
} else {
setValue(id, true);
}
- } else {
- markAsDirty();
}
}
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectNull.java b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectNull.java
new file mode 100644
index 0000000000..fb5914f395
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectNull.java
@@ -0,0 +1,25 @@
+package com.vaadin.tests.components.nativeselect;
+
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.NativeSelect;
+
+public class NativeSelectNull extends AbstractTestUIWithLog {
+ @Override
+ protected void setup(VaadinRequest request) {
+ NativeSelect nativeSelect = new NativeSelect();
+ nativeSelect.addItem("Item");
+ nativeSelect.addValueChangeListener(new ValueChangeListener() {
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ log("Value: " + event.getProperty().getValue());
+
+ }
+ });
+ addComponent(nativeSelect);
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectNullTest.java b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectNullTest.java
new file mode 100644
index 0000000000..613efbb566
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectNullTest.java
@@ -0,0 +1,20 @@
+package com.vaadin.tests.components.nativeselect;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.NativeSelectElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+import com.vaadin.tests.tb3.SingleBrowserTestPhantomJS2;
+
+public class NativeSelectNullTest extends SingleBrowserTestPhantomJS2 {
+ @Test
+ public void selectNull() {
+ openTestURL();
+ NativeSelectElement select = $(NativeSelectElement.class).first();
+ select.selectByText("Item");
+ Assert.assertEquals("1. Value: Item", getLogRow(0));
+ select.selectByText("");
+ Assert.assertEquals("2. Value: null", getLogRow(0));
+ }
+}