From 7c94854901dc862976f98bb527a3da43fa39bdbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sauli=20T=C3=A4hk=C3=A4p=C3=A4=C3=A4?= Date: Fri, 7 Nov 2014 00:00:24 +0200 Subject: [PATCH] Don't set null value for unmapped client side keys. (#15181) Change-Id: I7eab60daa74a9941e47a07fe7f9de0f94f155a78 --- server/src/com/vaadin/ui/AbstractSelect.java | 15 +++--- .../tree/SelectItemAfterRemove.java | 43 ++++++++++++++++ .../tree/SelectItemAfterRemoveTest.java | 49 +++++++++++++++++++ 3 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/tree/SelectItemAfterRemove.java create mode 100644 uitest/src/com/vaadin/tests/components/tree/SelectItemAfterRemoveTest.java diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index 9babf7e876..2714e0cbf5 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -532,13 +532,16 @@ public abstract class AbstractSelect extends AbstractField 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 index 0000000000..8002f5100e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tree/SelectItemAfterRemove.java @@ -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 index 0000000000..b048e185ea --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tree/SelectItemAfterRemoveTest.java @@ -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 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 getSpans() { + return findElements(By.tagName("span")); + } +} \ No newline at end of file -- 2.39.5