diff options
author | Artur Signell <artur@vaadin.com> | 2015-05-18 23:09:47 +0300 |
---|---|---|
committer | Mika Murtojarvi <mika@vaadin.com> | 2015-05-25 17:06:19 +0300 |
commit | d7ab3b798868f45af7e6c2768676b6aee1c902ba (patch) | |
tree | b5bf53287226e2be97c95c2c376c1a02432b024b | |
parent | 95793e663c2de5c163d461acb5133008de3e05c7 (diff) | |
download | vaadin-framework-d7ab3b798868f45af7e6c2768676b6aee1c902ba.tar.gz vaadin-framework-d7ab3b798868f45af7e6c2768676b6aee1c902ba.zip |
Ensure the whole hierarchy is refreshed when opening editor row (#17459)7.4.7
Change-Id: I3ecbe212a254d9883f42a4f1368bce6f2a33b402
4 files changed, 183 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index cae72c85f7..e372df85d0 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -4887,6 +4887,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..eb4ee4d28a --- /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.setColumnOrder("firstName", "lastName", "address.city"); + grid.setEditorEnabled(true); + Set<String> cities = new HashSet<String>(); + 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<String> { + 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<String> 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<ComplexPerson> container = ComplexPerson + .createContainer(size); + container.addNestedContainerBean("address"); + setContainerDataSource(container); + } +} |