summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Pöntelin <teemu@vaadin.com>2014-12-04 20:09:42 +0200
committerSauli Tähkäpää <sauli@vaadin.com>2014-12-16 22:52:32 +0200
commit6a9f18e592c9bd99e90d3886f96beaab6df7d064 (patch)
treeb0e85b174eddee0b88a84881efe7e8c503164b23
parent64ca4836e9c5224e86764b504459c795d4701c09 (diff)
downloadvaadin-framework-6a9f18e592c9bd99e90d3886f96beaab6df7d064.tar.gz
vaadin-framework-6a9f18e592c9bd99e90d3886f96beaab6df7d064.zip
Fix CustomLayout child rendering when template is missing (#8696)
Change-Id: I8ce4fbc566f030bf22c555f68b97beb781b19805
-rw-r--r--client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java23
-rw-r--r--uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithoutTemplate.java44
-rw-r--r--uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithoutTemplateTest.java43
3 files changed, 104 insertions, 6 deletions
diff --git a/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java b/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java
index a37ce9af38..80979587b9 100644
--- a/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java
+++ b/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java
@@ -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
index 0000000000..54949a053d
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithoutTemplate.java
@@ -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
index 0000000000..695d9cceff
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithoutTemplateTest.java
@@ -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());
+ }
+
+}