From b3b50eb368a8b6200200b6b1f1324d0fc63f4409 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Fri, 10 Apr 2015 16:24:32 +0300 Subject: [PATCH] Fix writing of child local ids in AbsoluteLayout (#17421) Change-Id: I49eb3246061e1b011a0f87e94d2a43eb20c31a34 --- server/src/com/vaadin/ui/AbsoluteLayout.java | 3 +- .../design/DesignContextLocalIdTest.java | 56 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/server/src/com/vaadin/ui/AbsoluteLayout.java b/server/src/com/vaadin/ui/AbsoluteLayout.java index 63bbe70157..303e8efd6b 100644 --- a/server/src/com/vaadin/ui/AbsoluteLayout.java +++ b/server/src/com/vaadin/ui/AbsoluteLayout.java @@ -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 diff --git a/server/tests/src/com/vaadin/tests/design/DesignContextLocalIdTest.java b/server/tests/src/com/vaadin/tests/design/DesignContextLocalIdTest.java index c3d7e6d8cf..dffeb2e412 100644 --- a/server/tests/src/com/vaadin/tests/design/DesignContextLocalIdTest.java +++ b/server/tests/src/com/vaadin/tests/design/DesignContextLocalIdTest.java @@ -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")); + } + } } -- 2.39.5