summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Tahvonen <matti@vaadin.com>2015-05-29 16:22:26 +0300
committerVaadin Code Review <review@vaadin.com>2015-06-08 07:19:26 +0000
commit5ae33b641eea02b647825b27c311d4116f3be838 (patch)
treecc731c84e62a14b7a3a621841cb7590ee3081f04
parentb0d5315e8ba95d099f93dc2d16339033a6525b59 (diff)
downloadvaadin-framework-5ae33b641eea02b647825b27c311d4116f3be838.tar.gz
vaadin-framework-5ae33b641eea02b647825b27c311d4116f3be838.zip
Selection is now shown although scrollToSelectedItem is false (#16673)
If scrollToSelectedItem is set to false (which is needed to work properly with large datasets) the selected item caption is sent to client with a special attribute to avoid the field looking like unselected. Change-Id: Ib80355c3b52faaaeaa9ab7195644701cc3bf0d15
-rw-r--r--client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java6
-rw-r--r--server/src/com/vaadin/ui/ComboBox.java7
-rw-r--r--uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabled.java74
-rw-r--r--uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabledTest.java44
4 files changed, 131 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
index 8757f46e71..1224a2eaf2 100644
--- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
+++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
@@ -173,6 +173,12 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
// started.
if (selectedKeys.length > 0 && !selectedKeys[0].equals("")) {
performSelection(selectedKeys[0]);
+ } else if (!getWidget().waitingForFilteringResponse
+ && uidl.hasAttribute("selectedCaption")) {
+ // scrolling to correct page is disabled, caption is passed as a
+ // special parameter
+ getWidget().tb.setText(uidl
+ .getStringAttribute("selectedCaption"));
} else {
resetSelection();
}
diff --git a/server/src/com/vaadin/ui/ComboBox.java b/server/src/com/vaadin/ui/ComboBox.java
index 4af93113f9..033ec3cd14 100644
--- a/server/src/com/vaadin/ui/ComboBox.java
+++ b/server/src/com/vaadin/ui/ComboBox.java
@@ -288,6 +288,13 @@ public class ComboBox extends AbstractSelect implements
// Paint variables
target.addVariable(this, "selected", selectedKeys);
+ if (getValue() != null && selectedKeys[0] == null) {
+ // not always available, e.g. scrollToSelectedIndex=false
+ // Give the caption for selected item still, not to make it look
+ // like there is no selection at all
+ target.addAttribute("selectedCaption",
+ getItemCaption(getValue()));
+ }
if (isNewItemsAllowed()) {
target.addVariable(this, "newitem", "");
}
diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabled.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabled.java
new file mode 100644
index 0000000000..f94306d2fa
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabled.java
@@ -0,0 +1,74 @@
+package com.vaadin.tests.components.combobox;
+
+import java.util.ArrayList;
+
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.tests.components.ComponentTestCase;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.Notification;
+
+public class ComboBoxScrollingToPageDisabled extends
+ ComponentTestCase<ComboBox> {
+
+ private static final Object CAPTION = "caption";
+
+ @Override
+ protected Class<ComboBox> getTestClass() {
+ return ComboBox.class;
+ }
+
+ @Override
+ protected void initializeComponents() {
+ ComboBox s = createSelect(null);
+ s.setScrollToSelectedItem(false);
+ populate(s, 100);
+ Object selection = new ArrayList<Object>(s.getItemIds()).get(50);
+ s.setValue(selection);
+ addTestComponent(s);
+ }
+
+ private void populate(ComboBox s, int nr) {
+ for (int i = 0; i < nr; i++) {
+ addItem(s, "Item " + i);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void addItem(ComboBox s, String string) {
+ Object id = s.addItem();
+ s.getItem(id).getItemProperty(CAPTION).setValue(string);
+
+ }
+
+ private ComboBox createSelect(String caption) {
+ final ComboBox cb = new ComboBox();
+ cb.setImmediate(true);
+ cb.addContainerProperty(CAPTION, String.class, "");
+ cb.setItemCaptionPropertyId(CAPTION);
+ cb.setCaption(caption);
+ cb.addValueChangeListener(new ValueChangeListener() {
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ Notification.show("Value now:" + cb.getValue() + " "
+ + cb.getItemCaption(cb.getValue()));
+
+ }
+ });
+ return cb;
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Test that selected value appears on the client "
+ + "side even though setScrollToSelectedItem(false) "
+ + "has been called. Textbox should containe 'Item 50'.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 16673;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabledTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabledTest.java
new file mode 100644
index 0000000000..8c09279b87
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabledTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.combobox;
+
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * When pressed down key, while positioned on the last item - should show next
+ * page and focus on the first item of the next page.
+ */
+public class ComboBoxScrollingToPageDisabledTest extends MultiBrowserTest {
+
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+ openTestURL();
+ }
+
+ @Test
+ public void checkValueIsVidinlr() throws InterruptedException {
+ WebElement input = driver.findElement(By
+ .className("v-filterselect-input"));
+ String value = input.getAttribute("value");
+ org.junit.Assert.assertEquals("Item 50", value);
+ }
+
+}