]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix writing of child local ids in AbsoluteLayout (#17421)
authorJohannes Dahlström <johannesd@vaadin.com>
Fri, 10 Apr 2015 13:24:32 +0000 (16:24 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 13 Apr 2015 07:44:34 +0000 (07:44 +0000)
Change-Id: I49eb3246061e1b011a0f87e94d2a43eb20c31a34

server/src/com/vaadin/ui/AbsoluteLayout.java
server/tests/src/com/vaadin/tests/design/DesignContextLocalIdTest.java

index 63bbe701575c3bf60eebe1cca6341440592a0b5c..303e8efd6b06381243482a3d4facc1c62a7a7557 100644 (file)
@@ -724,7 +724,7 @@ public class AbsoluteLayout extends AbstractLayout implements
         for (Component child : this) {
             Element childElement = designContext.createElement(child);
             design.appendChild(childElement);
-            child.writeDesign(childElement, designContext);
+
             // handle position
             ComponentPosition position = getPosition(child);
             writePositionAttribute(childElement, ATTR_TOP, position
@@ -735,6 +735,7 @@ public class AbsoluteLayout extends AbstractLayout implements
                     .getBottomUnits().getSymbol(), position.getBottomValue());
             writePositionAttribute(childElement, ATTR_LEFT, position
                     .getLeftUnits().getSymbol(), position.getLeftValue());
+
             // handle z-index
             if (position.getZIndex() >= 0) {
                 childElement
index c3d7e6d8cfffab5dbcbcc004bf7e27d64ac110c3..dffeb2e412ea41e9a717b52c36426348655e9407 100644 (file)
@@ -20,11 +20,25 @@ import static org.junit.Assert.assertEquals;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 
+import org.jsoup.nodes.Element;
 import org.junit.Test;
 
+import com.vaadin.ui.AbsoluteLayout;
+import com.vaadin.ui.Accordion;
 import com.vaadin.ui.Button;
+import com.vaadin.ui.ComponentContainer;
+import com.vaadin.ui.CssLayout;
+import com.vaadin.ui.CustomLayout;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.HorizontalSplitPanel;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.SingleComponentContainer;
+import com.vaadin.ui.TabSheet;
 import com.vaadin.ui.TextField;
 import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.VerticalSplitPanel;
+import com.vaadin.ui.Window;
 import com.vaadin.ui.declarative.Design;
 import com.vaadin.ui.declarative.DesignContext;
 
@@ -57,4 +71,46 @@ public class DesignContextLocalIdTest {
         assertEquals("Found the wrong component by local id.", ctx
                 .getComponentByLocalId("bar").getClass(), TextField.class);
     }
+
+    @Test
+    public void testWriteLocalId() {
+        DesignContext ctx = new DesignContext();
+
+        Button b = new Button();
+        ctx.setComponentLocalId(b, "button-id");
+
+        assertEquals("button-id", ctx.createElement(b).attr("_id"));
+    }
+
+    @Test
+    public void testWriteChildLocalIds() throws Exception {
+        DesignContext ctx = new DesignContext();
+
+        ComponentContainer[] ctrs = { new AbsoluteLayout(), new CssLayout(),
+                new GridLayout(1, 1), new CustomLayout(),
+                new HorizontalLayout(), new VerticalLayout(), new Accordion(),
+                new HorizontalSplitPanel(), new TabSheet(),
+                new VerticalSplitPanel() };
+
+        Button b = new Button();
+        ctx.setComponentLocalId(b, "button-id");
+
+        for (ComponentContainer ctr : ctrs) {
+            ctr.addComponent(b);
+            Element e = ctx.createElement(ctr);
+            assertEquals("Unexpected child local id for "
+                    + ctr.getClass().getSimpleName(), "button-id", e
+                    .getElementsByTag("v-button").first().attr("_id"));
+        }
+
+        SingleComponentContainer[] sctrs = { new Window(), new Panel() };
+
+        for (SingleComponentContainer ctr : sctrs) {
+            ctr.setContent(b);
+            Element e = ctx.createElement(ctr);
+            assertEquals("Unexpected child local id for "
+                    + ctr.getClass().getSimpleName(), "button-id", e
+                    .getElementsByTag("v-button").first().attr("_id"));
+        }
+    }
 }