diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-08-02 09:12:21 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-08-02 09:12:21 +0300 |
commit | f12a23c9c6bb176dd0550f07d6ddeb1e91c84bfc (patch) | |
tree | 70f177f117b87bcb20d6eb1f3fa46ba45251a976 /uitest/src/main | |
parent | 61c3a725bad98b731a8eb6a3186bb66398630022 (diff) | |
download | vaadin-framework-f12a23c9c6bb176dd0550f07d6ddeb1e91c84bfc.tar.gz vaadin-framework-f12a23c9c6bb176dd0550f07d6ddeb1e91c84bfc.zip |
Fix RadioButtonGroup selection updates to client (#9749)
This patch provides a simple fix for the majority of issues. There are still issues that should be fixes by refactoring parts of the logic in AbstractSingleSelect.
This patch does not unify the handling of empty values in the TestBench elements of various AbstractSingleSelects.
Fixes #9494
Diffstat (limited to 'uitest/src/main')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/abstractsingleselect/AbstractSingleSelection.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/abstractsingleselect/AbstractSingleSelection.java b/uitest/src/main/java/com/vaadin/tests/components/abstractsingleselect/AbstractSingleSelection.java new file mode 100644 index 0000000000..55f61b4134 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/abstractsingleselect/AbstractSingleSelection.java @@ -0,0 +1,68 @@ +package com.vaadin.tests.components.abstractsingleselect; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.data.provider.Query; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractSingleSelect; +import com.vaadin.ui.Button; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.NativeSelect; +import com.vaadin.ui.RadioButtonGroup; + +@Widgetset("com.vaadin.DefaultWidgetSet") +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class AbstractSingleSelection extends AbstractTestUI { + + /* Initial placeholder component */ + AbstractSingleSelect<String> component = new ComboBox<>(); + + @Override + protected void setup(VaadinRequest request) { + NativeSelect<Class<? extends AbstractSingleSelect>> componentSelect = new NativeSelect<>(); + componentSelect.setItems(RadioButtonGroup.class, NativeSelect.class, + ComboBox.class); + componentSelect.setItemCaptionGenerator(Class::getSimpleName); + + componentSelect.setEmptySelectionAllowed(false); + componentSelect.addValueChangeListener(singleSelectClass -> { + createComponent(singleSelectClass.getValue()); + }); + + addComponent(componentSelect); + addComponent(component); // This will be replaced in createComponent + addComponent( + new Button("Deselect", e -> component.setSelectedItem(null))); + addComponent(new Button("Select Bar", + e -> component.setSelectedItem("Bar"))); + addComponent(new Button("Refresh", + e -> component.getDataProvider().refreshAll())); + + // Select a value from native select to create the initial component + componentSelect.getDataProvider().fetch(new Query<>()).findFirst() + .ifPresent(componentSelect::setSelectedItem); + } + + private void createComponent( + Class<? extends AbstractSingleSelect> singleSelectClass) { + try { + AbstractSingleSelect<String> select = singleSelectClass + .newInstance(); + select.setItems("Foo", "Bar", "Baz", "Reset"); + select.setSelectedItem("Bar"); + + select.addValueChangeListener(e -> { + if ("Reset".equals(e.getValue())) { + select.setSelectedItem("Bar"); + } + }); + + select.setId("testComponent"); + + replaceComponent(component, select); + component = select; + } catch (InstantiationException | IllegalAccessException e1) { + throw new RuntimeException("Component creation failed", e1); + } + } +} |