Browse Source

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
tags/7.5.0.rc1
Matti Tahvonen 9 years ago
parent
commit
5ae33b641e

+ 6
- 0
client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java View 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();
}

+ 7
- 0
server/src/com/vaadin/ui/ComboBox.java View 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", "");
}

+ 74
- 0
uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabled.java View File

@@ -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;
}

}

+ 44
- 0
uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingToPageDisabledTest.java View File

@@ -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);
}

}

Loading…
Cancel
Save