]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix CustomLayout child rendering when template is missing (#8696)
authorTeemu Pöntelin <teemu@vaadin.com>
Thu, 4 Dec 2014 18:09:42 +0000 (20:09 +0200)
committerVaadin Code Review <review@vaadin.com>
Wed, 10 Dec 2014 17:55:25 +0000 (17:55 +0000)
Change-Id: I8ce4fbc566f030bf22c555f68b97beb781b19805

client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java
uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithoutTemplate.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithoutTemplateTest.java [new file with mode: 0644]

index a37ce9af3847aaa62b45299ee1901af071587c80..80979587b91fb37b1c1cae535d39ffb286f9f562 100644 (file)
@@ -34,6 +34,8 @@ import com.vaadin.ui.CustomLayout;
 public class CustomLayoutConnector extends AbstractLayoutConnector implements
         SimpleManagedLayout, Paintable {
 
+    private boolean templateUpdated;
+
     @Override
     public CustomLayoutState getState() {
         return (CustomLayoutState) super.getState();
@@ -62,7 +64,7 @@ public class CustomLayoutConnector extends AbstractLayoutConnector implements
     }
 
     private void updateHtmlTemplate() {
-        if (getWidget().hasTemplate()) {
+        if (templateUpdated) {
             // We (currently) only do this once. You can't change the template
             // later on.
             return;
@@ -76,14 +78,23 @@ public class CustomLayoutConnector extends AbstractLayoutConnector implements
             templateContents = getConnection().getResource(
                     "layouts/" + templateName + ".html");
             if (templateContents == null) {
-                templateContents = "<em>Layout file layouts/"
-                        + templateName
-                        + ".html is missing. Components will be drawn for debug purposes.</em>";
+                // Template missing -> show debug notice and render components
+                // in order.
+                getWidget()
+                        .getElement()
+                        .setInnerHTML(
+                                "<em>Layout file layouts/"
+                                        + templateName
+                                        + ".html is missing. Components will be drawn for debug purposes.</em>");
             }
         }
 
-        getWidget().initializeHTML(templateContents,
-                getConnection().getThemeUri());
+        if (templateContents != null) {
+            // Template ok -> initialize.
+            getWidget().initializeHTML(templateContents,
+                    getConnection().getThemeUri());
+        }
+        templateUpdated = true;
     }
 
     @Override
diff --git a/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithoutTemplate.java b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithoutTemplate.java
new file mode 100644 (file)
index 0000000..54949a0
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.components.customlayout;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CustomLayout;
+import com.vaadin.ui.Label;
+
+public class CustomLayoutWithoutTemplate extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        CustomLayout cl = new CustomLayout("missing-layout-file.html");
+        cl.addComponent(new Label("This Label should be visible."), "foo");
+        cl.addComponent(new Button("And this Button too."), "bar");
+
+        addComponent(cl);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Verify that CustomLayout renders child components even if the template is missing.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 8696;
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithoutTemplateTest.java b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithoutTemplateTest.java
new file mode 100644 (file)
index 0000000..695d9cc
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.components.customlayout;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.ElementQuery;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.CustomLayoutElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class CustomLayoutWithoutTemplateTest extends SingleBrowserTest {
+
+    @Test
+    public void testChildComponents() {
+        openTestURL();
+
+        ElementQuery<CustomLayoutElement> customLayout = $(CustomLayoutElement.class);
+
+        // Verify the Button and Label are rendered inside the CustomLayout.
+        assertTrue("Button was not rendered.",
+                customLayout.$(ButtonElement.class).exists());
+        assertTrue("Label was not rendered.", customLayout
+                .$(LabelElement.class).exists());
+    }
+
+}