From d505fc70ac3bbf13e868c227b58d82966abf2254 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 23 Jun 2015 23:20:59 +0300 Subject: [PATCH] Handle nested GridLayouts in declarative format correctly (#18312) Change-Id: Id7f204c170981f4395e789333b89cd8207fe4002 --- server/src/com/vaadin/ui/GridLayout.java | 12 ++++--- .../gridlayout/GridLayoutDeclarativeTest.java | 33 +++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/server/src/com/vaadin/ui/GridLayout.java b/server/src/com/vaadin/ui/GridLayout.java index 6ccb272704..792ad72dcc 100644 --- a/server/src/com/vaadin/ui/GridLayout.java +++ b/server/src/com/vaadin/ui/GridLayout.java @@ -1319,11 +1319,15 @@ public class GridLayout extends AbstractLayout implements setMargin(readMargin(design, getMargin(), designContext)); - // Prepare a 2D map for reading column contents - Elements rowElements = design.getElementsByTag("row"); + List rowElements = new ArrayList(); List> rows = new ArrayList>(); - for (int i = 0; i < rowElements.size(); ++i) { - rows.add(new HashMap()); + // Prepare a 2D map for reading column contents + for (Element e : design.children()) { + if (e.tagName().equalsIgnoreCase("row")) { + rowElements.add(e); + rows.add(new HashMap()); + + } } setRows(Math.max(rows.size(), 1)); diff --git a/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java index 9d3b5001da..d69fd92984 100644 --- a/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java @@ -203,4 +203,37 @@ public class GridLayoutDeclarativeTest extends } return result; } + + @Test + public void testNestedGridLayouts() { + String design = "" + // + "" + // + " " + // + " " + // + " " + // + " " + // + " " + // + " " + // + " " + // + " " + // + " Button " + // + " " + // + " " + // + " " + // + " " + // + " " + // + " " + // + " " + // + " " + // + ""; + GridLayout outer = new GridLayout(); + GridLayout inner = new GridLayout(); + Button b = new Button("Button"); + b.setCaptionAsHtml(true); + inner.addComponent(b); + outer.addComponent(inner); + testRead(design, outer); + testWrite(design, outer); + + } } -- 2.39.5