From f12a23c9c6bb176dd0550f07d6ddeb1e91c84bfc Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 2 Aug 2017 09:12:21 +0300 Subject: 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 --- .../AbstractSingleSelection.java | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/abstractsingleselect/AbstractSingleSelection.java (limited to 'uitest/src/main') 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 component = new ComboBox<>(); + + @Override + protected void setup(VaadinRequest request) { + NativeSelect> 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 singleSelectClass) { + try { + AbstractSingleSelect 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); + } + } +} -- cgit v1.2.3