From 1af2ebc79dee66d90a5927e647ef41bea5aecdc1 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 18 May 2015 23:09:47 +0300 Subject: [PATCH] Ensure the whole hierarchy is refreshed when opening editor row (#17459) Change-Id: Iff691f27b70ccbad004dbc55411be977c5acff03 --- server/src/com/vaadin/ui/Grid.java | 7 ++ .../grid/GridEditorCustomField.java | 102 ++++++++++++++++++ .../grid/GridEditorCustomFieldTest.java | 44 ++++++++ .../tests/components/grid/PersonTestGrid.java | 30 ++++++ 4 files changed, 183 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/grid/GridEditorCustomField.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/PersonTestGrid.java diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 5cc1a6752e..282711aa92 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -5688,6 +5688,13 @@ public class Grid extends AbstractComponent implements SelectionNotifier, column.getState().editorConnector = getEditorField(column .getPropertyId()); } + + // Must ensure that all fields, recursively, are sent to the client + // This is needed because the fields are hidden using isRendered + for (Field f : getEditorFields()) { + f.markAsDirtyRecursive(); + } + } private void setEditorField(Object propertyId, Field field) { diff --git a/uitest/src/com/vaadin/tests/components/grid/GridEditorCustomField.java b/uitest/src/com/vaadin/tests/components/grid/GridEditorCustomField.java new file mode 100644 index 0000000000..4703c98994 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridEditorCustomField.java @@ -0,0 +1,102 @@ +/* + * 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.grid; + +import java.util.HashSet; +import java.util.Set; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.fieldgroup.ComplexPerson; +import com.vaadin.ui.Button; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.CustomField; +import com.vaadin.ui.Grid; +import com.vaadin.ui.HorizontalLayout; + +@Theme("valo") +public class GridEditorCustomField extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new PersonTestGrid(100); + grid.setWidth("800px"); + grid.setColumns("firstName", "lastName", "address.city"); + grid.setEditorEnabled(true); + Set cities = new HashSet(); + for (Object o : grid.getContainerDataSource().getItemIds()) { + ComplexPerson p = (ComplexPerson) o; + cities.add(p.getAddress().getCity()); + } + CustomCitySelect cityEditor = new CustomCitySelect( + cities.toArray(new String[cities.size()])); + grid.getColumn("address.city").setEditorField(cityEditor); + addComponent(grid); + } + + public static class CustomCitySelect extends CustomField { + private HorizontalLayout fieldLayout; + private String[] values; + private ComboBox cityComboBox; + + public CustomCitySelect(String... values) { + this.values = values; + } + + @Override + protected Component initContent() { + fieldLayout = new HorizontalLayout(); + fieldLayout.setWidth("100%"); + + cityComboBox = new ComboBox(); + for (String value : values) { + cityComboBox.addItem(value); + } + fieldLayout.addComponent(cityComboBox); + fieldLayout.setExpandRatio(cityComboBox, 1.0f); + + Button addCountryButton = new Button("New"); + fieldLayout.addComponent(addCountryButton); + + return fieldLayout; + } + + @Override + public Class getType() { + return String.class; + } + + @Override + protected void setInternalValue(String newValue) { + super.setInternalValue(newValue); + if (cityComboBox == null) { + return; + } + cityComboBox.setValue(newValue); + } + + @Override + public String getInternalValue() { + if (cityComboBox == null) { + return null; + } + return (String) cityComboBox.getValue(); + } + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java b/uitest/src/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java new file mode 100644 index 0000000000..3187e629c1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.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.grid; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridEditorElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridEditorCustomFieldTest extends MultiBrowserTest { + + @Test + public void testCustomFieldWorksInEditorRow() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + Assert.assertEquals("Stockholm", grid.getCell(0, 2).getText()); + grid.getCell(0, 1).doubleClick(); + GridEditorElement editor = grid.getEditor(); + TestBenchElement customField = editor.getField(2); + + ComboBoxElement comboBox = customField.$(ComboBoxElement.class).first(); + comboBox.selectByText("Oslo"); + editor.save(); + Assert.assertEquals("Oslo", grid.getCell(0, 2).getText()); + + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/PersonTestGrid.java b/uitest/src/com/vaadin/tests/components/grid/PersonTestGrid.java new file mode 100644 index 0000000000..f654cd153d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/PersonTestGrid.java @@ -0,0 +1,30 @@ +/* + * 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.grid; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.tests.fieldgroup.ComplexPerson; +import com.vaadin.ui.Grid; + +public class PersonTestGrid extends Grid { + + public PersonTestGrid(int size) { + BeanItemContainer container = ComplexPerson + .createContainer(size); + container.addNestedContainerBean("address"); + setContainerDataSource(container); + } +} -- 2.39.5