]> source.dussan.org Git - vaadin-framework.git/commitdiff
Don't set null value for unmapped client side keys. (#15181)
authorSauli Tähkäpää <sauli@vaadin.com>
Thu, 6 Nov 2014 22:00:24 +0000 (00:00 +0200)
committerTeemu Suo-Anttila <teemusa@vaadin.com>
Tue, 8 Mar 2016 12:03:43 +0000 (14:03 +0200)
Change-Id: I7eab60daa74a9941e47a07fe7f9de0f94f155a78

server/src/com/vaadin/ui/AbstractSelect.java
uitest/src/com/vaadin/tests/components/tree/SelectItemAfterRemove.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/tree/SelectItemAfterRemoveTest.java [new file with mode: 0644]

index 9babf7e876c5f258ac637c3fd12a3ba24b5ba3d7..2714e0cbf59843990b410355a4ba9fec05057a2a 100644 (file)
@@ -532,13 +532,16 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
                 } else {
                     final Object id = itemIdMapper
                             .get(clientSideSelectedKeys[0]);
-                    if (!isNullSelectionAllowed() && id == null) {
-                        markAsDirty();
-                    } else if (id != null
-                            && id.equals(getNullSelectionItemId())) {
-                        setValue(null, true);
+
+                    if (id != null) {
+                        if (isNullSelectionAllowed()
+                                && id.equals(getNullSelectionItemId())) {
+                            setValue(null, true);
+                        } else {
+                            setValue(id, true);
+                        }
                     } else {
-                        setValue(id, true);
+                        markAsDirty();
                     }
                 }
             }
diff --git a/uitest/src/com/vaadin/tests/components/tree/SelectItemAfterRemove.java b/uitest/src/com/vaadin/tests/components/tree/SelectItemAfterRemove.java
new file mode 100644 (file)
index 0000000..8002f51
--- /dev/null
@@ -0,0 +1,43 @@
+package com.vaadin.tests.components.tree;
+
+import com.vaadin.event.ItemClickEvent;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Tree;
+
+public class SelectItemAfterRemove extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        final Tree tree = new Tree();
+
+        tree.setImmediate(true);
+        tree.addItemClickListener(new ItemClickEvent.ItemClickListener() {
+            @Override
+            public void itemClick(ItemClickEvent event) {
+
+                tree.removeItem(tree.getValue());
+                tree.select(event.getItemId());
+            }
+        });
+
+        tree.addItem("first");
+        tree.addItem("second");
+        tree.addItem("third");
+
+        tree.select("first");
+
+        addComponent(tree);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Clicking on an item should select the clicked item and remove "
+                + "the previously selected item.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 15181;
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/components/tree/SelectItemAfterRemoveTest.java b/uitest/src/com/vaadin/tests/components/tree/SelectItemAfterRemoveTest.java
new file mode 100644 (file)
index 0000000..b048e18
--- /dev/null
@@ -0,0 +1,49 @@
+package com.vaadin.tests.components.tree;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class SelectItemAfterRemoveTest extends MultiBrowserTest {
+
+    @Test
+    public void selectedItemIsSelected() {
+        openTestURL();
+
+        getSecondSpan().click();
+
+        assertThat(getNodes().size(), is(2));
+        assertThat(getFirstNode().getAttribute("class"),
+                containsString("v-tree-node-selected"));
+    }
+
+    private WebElement getFirstNode() {
+        return getNodes().get(0);
+    }
+
+    private List<WebElement> getNodes() {
+        return findElements(By.className("v-tree-node-caption"));
+    }
+
+    private WebElement getSecondSpan() {
+        for (WebElement e : getSpans()) {
+            if (e.getText().equals("second")) {
+                return e;
+            }
+        }
+
+        return null;
+    }
+
+    private List<WebElement> getSpans() {
+        return findElements(By.tagName("span"));
+    }
+}
\ No newline at end of file