]> source.dussan.org Git - vaadin-framework.git/commitdiff
Selection is now shown although scrollToSelectedItem is false (#16673)
authorMatti Tahvonen <matti@vaadin.com>
Fri, 29 May 2015 13:22:26 +0000 (16:22 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 8 Jun 2015 07:19:26 +0000 (07:19 +0000)
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

client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
server/src/com/vaadin/ui/ComboBox.java
uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabled.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabledTest.java [new file with mode: 0644]

index 8757f46e71c54fc7612d9b73e426807a9d96c7a4..1224a2eaf2bd64d831ad05aa5f86ee25c3ce0b21 100644 (file)
@@ -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();
             }
index 4af93113f9ee4002e464e07439376502fc86a42d..033ec3cd14673bf54ac81b96db47d442356110a2 100644 (file)
@@ -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 (file)
index 0000000..f94306d
--- /dev/null
@@ -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 (file)
index 0000000..8c09279
--- /dev/null
@@ -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);
+    }
+
+}