From 8f81ba9505520ba5fb44994710c08b69c273947a Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 9 Jun 2015 15:41:25 +0300 Subject: Support string data in javascript renderers (#18209) Change-Id: I2be48aa7a60920193a2f4bd9a413979cb9c48f34 --- .../tests/components/grid/JavaScriptRenderers.java | 4 +++ .../components/grid/JavaScriptRenderersTest.java | 4 +++ .../components/grid/JavaScriptStringRenderer.java | 29 ++++++++++++++++++++++ .../components/grid/JavaScriptStringRenderer.js | 5 ++++ 4 files changed, 42 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/grid/JavaScriptStringRenderer.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/JavaScriptStringRenderer.js (limited to 'uitest/src/com/vaadin') diff --git a/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderers.java b/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderers.java index 4bfa244c22..8f88883161 100644 --- a/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderers.java +++ b/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderers.java @@ -55,6 +55,7 @@ public class JavaScriptRenderers extends AbstractTestUI { IndexedContainer container = new IndexedContainer(); container.addContainerProperty("id", Integer.class, Integer.valueOf(0)); container.addContainerProperty("bean", MyBean.class, null); + container.addContainerProperty("string", String.class, ""); for (int i = 0; i < 1000; i++) { Integer itemId = Integer.valueOf(i); @@ -62,6 +63,7 @@ public class JavaScriptRenderers extends AbstractTestUI { item.getItemProperty("id").setValue(itemId); item.getItemProperty("bean").setValue( new MyBean(i + 1, Integer.toString(i - 1))); + item.getItemProperty("string").setValue("string" + i); } Grid grid = new Grid(container); @@ -69,6 +71,8 @@ public class JavaScriptRenderers extends AbstractTestUI { grid.getColumn("bean").setRenderer(new MyBeanJSRenderer()); grid.getColumn("bean").setWidth(250); + grid.getColumn("string").setRenderer(new JavaScriptStringRenderer()); + addComponent(grid); } diff --git a/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java b/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java index 2e86053ef3..917245188a 100644 --- a/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java @@ -34,9 +34,13 @@ public class JavaScriptRenderersTest extends MultiBrowserTest { GridElement grid = $(GridElement.class).first(); GridCellElement cell_1_1 = grid.getCell(1, 1); + GridCellElement cell_2_2 = grid.getCell(2, 2); + // Verify render functionality Assert.assertEquals("Bean(2, 0)", cell_1_1.getText()); + Assert.assertEquals("string2", cell_2_2.getText()); + // Verify init functionality Assert.assertEquals("1", cell_1_1.getAttribute("column")); diff --git a/uitest/src/com/vaadin/tests/components/grid/JavaScriptStringRenderer.java b/uitest/src/com/vaadin/tests/components/grid/JavaScriptStringRenderer.java new file mode 100644 index 0000000000..ab3be6f4f1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/JavaScriptStringRenderer.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("JavaScriptStringRenderer.js") +public class JavaScriptStringRenderer extends + AbstractJavaScriptRenderer { + + protected JavaScriptStringRenderer() { + super(String.class); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/JavaScriptStringRenderer.js b/uitest/src/com/vaadin/tests/components/grid/JavaScriptStringRenderer.js new file mode 100644 index 0000000000..475b453dcc --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/JavaScriptStringRenderer.js @@ -0,0 +1,5 @@ +com_vaadin_tests_components_grid_JavaScriptStringRenderer = function() { + this.render = function(cell, data) { + cell.element.textContent = data; + } +} \ No newline at end of file -- cgit v1.2.3