summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/ui/Grid.java28
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java7
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridInlineDataDeclarativeTest.java106
3 files changed, 138 insertions, 3 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index 3b602abf1a..4fda7f7288 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -98,6 +98,7 @@ import com.vaadin.shared.util.SharedUtil;
import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;
import com.vaadin.ui.declarative.DesignException;
+import com.vaadin.ui.renderers.HtmlRenderer;
import com.vaadin.ui.renderers.Renderer;
import com.vaadin.ui.renderers.TextRenderer;
import com.vaadin.util.ReflectTools;
@@ -5468,7 +5469,19 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
if (child.tagName().equals("thead")) {
header.readDesign(child, context);
} else if (child.tagName().equals("tbody")) {
- // TODO: Inline data
+ for (Element row : child.children()) {
+ Elements cells = row.children();
+ Object[] data = new String[cells.size()];
+ for (int c = 0; c < cells.size(); ++c) {
+ data[c] = cells.get(c).html();
+ }
+ addRow(data);
+ }
+
+ // Since inline data is used, set HTML renderer for columns
+ for (Column c : getColumns()) {
+ c.setRenderer(new HtmlRenderer());
+ }
} else if (child.tagName().equals("tfoot")) {
footer.readDesign(child, context);
}
@@ -5529,7 +5542,18 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
// Always write thead. Reads correctly when there no header rows
header.writeDesign(tableElement.appendElement("thead"), context);
- // TODO: Body
+ if (context.shouldWriteData(this)) {
+ Element bodyElement = tableElement.appendElement("tbody");
+ for (Object itemId : datasource.getItemIds()) {
+ Element tableRow = bodyElement.appendElement("tr");
+ for (Column c : getColumns()) {
+ Object value = datasource.getItem(itemId)
+ .getItemProperty(c.getPropertyId()).getValue();
+ tableRow.appendElement("td").append(
+ (value != null ? value.toString() : ""));
+ }
+ }
+ }
if (footer.getRowCount() > 0) {
footer.writeDesign(tableElement.appendElement("tfoot"), context);
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java
index 0a32ec1734..2a4b3f01fc 100644
--- a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java
+++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java
@@ -35,6 +35,11 @@ public class GridDeclarativeTestBase extends DeclarativeTestBase<Grid> {
}
public Grid testRead(String design, Grid expected, boolean retestWrite) {
+ return testRead(design, expected, retestWrite, false);
+ }
+
+ public Grid testRead(String design, Grid expected, boolean retestWrite,
+ boolean writeData) {
Grid actual = super.testRead(design, expected);
compareGridColumns(expected, actual);
@@ -42,7 +47,7 @@ public class GridDeclarativeTestBase extends DeclarativeTestBase<Grid> {
compareFooters(expected, actual);
if (retestWrite) {
- testWrite(design, actual);
+ testWrite(design, actual, writeData);
}
return actual;
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridInlineDataDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridInlineDataDeclarativeTest.java
new file mode 100644
index 0000000000..fefd49a587
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridInlineDataDeclarativeTest.java
@@ -0,0 +1,106 @@
+/*
+ * 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.server.component.grid.declarative;
+
+import org.junit.Test;
+
+import com.vaadin.ui.Grid;
+
+public class GridInlineDataDeclarativeTest extends GridDeclarativeTestBase {
+
+ @Test
+ public void testSimpleInlineData() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Col1' />"
+ + "</colgroup>" //
+ + "<thead />" // No headers read or written
+ + "<tbody>" //
+ + "<tr><td>Foo</tr>" //
+ + "<tr><td>Bar</tr>" //
+ + "<tr><td>Baz</tr>" //
+ + "</table></v-grid>";
+
+ Grid grid = new Grid();
+ grid.addColumn("Col1", String.class);
+ grid.addRow("Foo");
+ grid.addRow("Bar");
+ grid.addRow("Baz");
+
+ // Remove default header
+ grid.removeHeaderRow(grid.getDefaultHeaderRow());
+
+ testWrite(design, grid, true);
+ testRead(design, grid, true, true);
+ }
+
+ @Test
+ public void testMultipleColumnsInlineData() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Col1' />"
+ + " <col sortable=true property-id='Col2' />"
+ + " <col sortable=true property-id='Col3' />" //
+ + "</colgroup>" //
+ + "<thead />" // No headers read or written
+ + "<tbody>" //
+ + "<tr><td>Foo<td>Bar<td>Baz</tr>" //
+ + "<tr><td>My<td>Summer<td>Car</tr>" //
+ + "</table></v-grid>";
+
+ Grid grid = new Grid();
+ grid.addColumn("Col1", String.class);
+ grid.addColumn("Col2", String.class);
+ grid.addColumn("Col3", String.class);
+ grid.addRow("Foo", "Bar", "Baz");
+ grid.addRow("My", "Summer", "Car");
+
+ // Remove default header
+ grid.removeHeaderRow(grid.getDefaultHeaderRow());
+
+ testWrite(design, grid, true);
+ testRead(design, grid, true, true);
+ }
+
+ @Test
+ public void testMultipleColumnsInlineDataReordered() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Col2' />"
+ + " <col sortable=true property-id='Col3' />"
+ + " <col sortable=true property-id='Col1' />" //
+ + "</colgroup>" //
+ + "<thead />" // No headers read or written
+ + "<tbody>" //
+ + "<tr><td>Bar<td>Baz<td>Foo</tr>" //
+ + "<tr><td>Summer<td>Car<td>My</tr>" //
+ + "</table></v-grid>";
+
+ Grid grid = new Grid();
+ grid.addColumn("Col1", String.class);
+ grid.addColumn("Col2", String.class);
+ grid.addColumn("Col3", String.class);
+ grid.addRow("Foo", "Bar", "Baz");
+ grid.addRow("My", "Summer", "Car");
+ grid.setColumnOrder("Col2", "Col3", "Col1");
+
+ // Remove default header
+ grid.removeHeaderRow(grid.getDefaultHeaderRow());
+
+ testWrite(design, grid, true);
+ testRead(design, grid, true, true);
+ }
+}