diff options
author | Artur <artur@vaadin.com> | 2017-02-01 16:49:16 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2017-02-01 16:49:16 +0200 |
commit | 697cfcf3d1720022d3b8ea1380ba76b50b2f8e3f (patch) | |
tree | 559f8dc6123fbb7999d5a8129267c1134d93075e /uitest | |
parent | 32c3c84e8476955792d0e08965ccdd006d8f3a18 (diff) | |
download | vaadin-framework-697cfcf3d1720022d3b8ea1380ba76b50b2f8e3f.tar.gz vaadin-framework-697cfcf3d1720022d3b8ea1380ba76b50b2f8e3f.zip |
Call "destroy" instead of "destory" in JavaScriptRenders (#8263)
* Call "destroy" instead of "destory" in JavaScriptRenders
For backwards compatibility, calls "destory" if no "destroy" exists
Fixes #8162
* Merge branch '7.7' into _js-renderer-destory
* Merge branch '7.7' into _js-renderer-destory
* Merge branch '7.7' into _js-renderer-destory
* Merge branch '7.7' into _js-renderer-destory
* Merge branch '7.7' into _js-renderer-destory
Diffstat (limited to 'uitest')
5 files changed, 95 insertions, 3 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptRenderers.java b/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptRenderers.java index bb7a93d378..d6a6373541 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptRenderers.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptRenderers.java @@ -19,10 +19,16 @@ import com.vaadin.data.Item; import com.vaadin.data.util.IndexedContainer; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Grid; +import com.vaadin.ui.Label; public class JavaScriptRenderers extends AbstractTestUI { + private Grid grid; + public static class MyBean { private int integer; private String string; @@ -52,10 +58,11 @@ public class JavaScriptRenderers extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { - IndexedContainer container = new IndexedContainer(); + final IndexedContainer container = new IndexedContainer(); container.addContainerProperty("id", Integer.class, Integer.valueOf(0)); container.addContainerProperty("bean", MyBean.class, null); container.addContainerProperty("string", String.class, ""); + container.addContainerProperty("string2", String.class, ""); for (int i = 0; i < 1000; i++) { Integer itemId = Integer.valueOf(i); @@ -65,15 +72,34 @@ public class JavaScriptRenderers extends AbstractTestUI { .setValue(new MyBean(i + 1, Integer.toString(i - 1))); item.getItemProperty("string").setValue("string" + i); } + Label clientLog = new Label(); + clientLog.setId("clientLog"); + addComponent(clientLog); + grid = createGrid(container); + addComponent(grid); + + addComponent(new Button("Recreate grid", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + Grid newGrid = createGrid(container); + replaceComponent(grid, newGrid); + grid = newGrid; + } + })); + } + + private Grid createGrid(IndexedContainer container) { Grid grid = new Grid(container); grid.getColumn("bean").setRenderer(new MyBeanJSRenderer()); grid.getColumn("bean").setWidth(250); grid.getColumn("string").setRenderer(new JavaScriptStringRenderer()); - - addComponent(grid); + grid.getColumn("string2") + .setRenderer(new JavaScriptStringRendererWithDestoryMethod()); + return grid; } } diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptStringRendererWithDestoryMethod.java b/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptStringRendererWithDestoryMethod.java new file mode 100644 index 0000000000..990a3617bd --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptStringRendererWithDestoryMethod.java @@ -0,0 +1,29 @@ +/* + * 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.annotations.JavaScript; +import com.vaadin.ui.renderers.AbstractJavaScriptRenderer; + +@JavaScript("JavaScriptStringRendererWithDestoryMethod.js") +public class JavaScriptStringRendererWithDestoryMethod + extends AbstractJavaScriptRenderer<String> { + + protected JavaScriptStringRendererWithDestoryMethod() { + super(String.class); + } + +} diff --git a/uitest/src/main/resources/com/vaadin/tests/components/grid/JavaScriptStringRenderer.js b/uitest/src/main/resources/com/vaadin/tests/components/grid/JavaScriptStringRenderer.js index e3061bf12f..44467cd59f 100644 --- a/uitest/src/main/resources/com/vaadin/tests/components/grid/JavaScriptStringRenderer.js +++ b/uitest/src/main/resources/com/vaadin/tests/components/grid/JavaScriptStringRenderer.js @@ -4,4 +4,9 @@ com_vaadin_tests_components_grid_JavaScriptStringRenderer = function() { // This one is for IE8 cell.element.innerText = data; } + + this.destroy = function(cell) { + document.getElementById("clientLog").innerHTML += "destroy: "+cell.rowIndex+"/"+cell.columnIndex+"<br>"; + } + }
\ No newline at end of file diff --git a/uitest/src/main/resources/com/vaadin/tests/components/grid/JavaScriptStringRendererWithDestoryMethod.js b/uitest/src/main/resources/com/vaadin/tests/components/grid/JavaScriptStringRendererWithDestoryMethod.js new file mode 100644 index 0000000000..8b6b8ede0b --- /dev/null +++ b/uitest/src/main/resources/com/vaadin/tests/components/grid/JavaScriptStringRendererWithDestoryMethod.js @@ -0,0 +1,12 @@ +com_vaadin_tests_components_grid_JavaScriptStringRendererWithDestoryMethod = function() { + this.render = function(cell, data) { + cell.element.textContent = data; + // This one is for IE8 + cell.element.innerText = data; + } + + this.destory = function(cell) { + document.getElementById("clientLog").innerHTML += "destory: "+cell.rowIndex+"/"+cell.columnIndex+"<br>"; + } + +}
\ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java index 803c3cedf1..4cc5125721 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java @@ -17,7 +17,10 @@ package com.vaadin.tests.components.grid; import org.junit.Assert; import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import com.vaadin.testbench.elements.ButtonElement; import com.vaadin.testbench.elements.GridElement; import com.vaadin.testbench.elements.GridElement.GridCellElement; import com.vaadin.testbench.parallel.TestCategory; @@ -49,4 +52,21 @@ public class JavaScriptRenderersTest extends MultiBrowserTest { Assert.assertTrue( cell_1_1.getText().startsWith("Clicked 1 with key 2 at")); } + + @Test + public void testJavaScriptRendererDestroy() { + openTestURL("debug"); + waitForDebugMessage( + "Your JavaScript connector (com_vaadin_tests_components_grid_JavaScriptStringRendererWithDestoryMethod) has a typo. The destory method should be renamed to destroy."); + + $(ButtonElement.class).first().click(); + + WebElement log = findElement(By.id("clientLog")); + String text = log.getText(); + Assert.assertTrue(text.contains("destory: 19/3")); + Assert.assertTrue(text.contains("destroy: 19/2")); + Assert.assertTrue(text.contains("destroy: 0/2")); + Assert.assertTrue(text.contains("destory: 0/3")); + } + } |