]> source.dussan.org Git - vaadin-framework.git/commitdiff
Handle nested GridLayouts in declarative format correctly (#18312)
authorArtur Signell <artur@vaadin.com>
Tue, 23 Jun 2015 20:20:59 +0000 (23:20 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 24 Jun 2015 06:28:20 +0000 (06:28 +0000)
Change-Id: Id7f204c170981f4395e789333b89cd8207fe4002

server/src/com/vaadin/ui/GridLayout.java
server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java

index 6ccb272704bc5a05ac84276845f0d958e491590b..792ad72dcc115332810db5f1e8d6b715387435eb 100644 (file)
@@ -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<Element> rowElements = new ArrayList<Element>();
         List<Map<Integer, Component>> rows = new ArrayList<Map<Integer, Component>>();
-        for (int i = 0; i < rowElements.size(); ++i) {
-            rows.add(new HashMap<Integer, Component>());
+        // 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<Integer, Component>());
+
+            }
         }
         setRows(Math.max(rows.size(), 1));
 
index 9d3b5001dabe4f9e97d2eae78911564b5ba63a8b..d69fd929848bd0341978fb02a5a4c007093f9b38 100644 (file)
@@ -203,4 +203,37 @@ public class GridLayoutDeclarativeTest extends
         }
         return result;
     }
+
+    @Test
+    public void testNestedGridLayouts() {
+        String design = "<!DOCTYPE html>" + //
+                "<html>" + //
+                " <body> " + //
+                "  <v-grid-layout> " + //
+                "   <row> " + //
+                "    <column> " + //
+                "     <v-grid-layout> " + //
+                "      <row> " + //
+                "       <column> " + //
+                "        <v-button>" + //
+                "          Button " + //
+                "        </v-button> " + //
+                "       </column> " + //
+                "      </row> " + //
+                "     </v-grid-layout> " + //
+                "    </column> " + //
+                "   </row> " + //
+                "  </v-grid-layout>  " + //
+                " </body>" + //
+                "</html>";
+        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);
+
+    }
 }