diff options
author | Artur Signell <artur@vaadin.com> | 2015-04-29 14:30:55 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-05-04 07:05:40 +0000 |
commit | dd05b436d9f74e9daa54829db3c73ff473d18acd (patch) | |
tree | 23971c5b21c1742ca6d976f0f1dcf43b34496cd9 | |
parent | 1fcd9a83b9760c82ba524016daf257b3cc706cab (diff) | |
download | vaadin-framework-dd05b436d9f74e9daa54829db3c73ff473d18acd.tar.gz vaadin-framework-dd05b436d9f74e9daa54829db3c73ff473d18acd.zip |
Render CustomLayout properly even if a slot is missing (#17681)
Change-Id: I1ca0699776b93987c00a23a61a64ba8f3b4cd95e
5 files changed, 128 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VCustomLayout.java b/client/src/com/vaadin/client/ui/VCustomLayout.java index 5f8a8197d0..0ee50fe0dd 100644 --- a/client/src/com/vaadin/client/ui/VCustomLayout.java +++ b/client/src/com/vaadin/client/ui/VCustomLayout.java @@ -305,6 +305,10 @@ public class VCustomLayout extends ComplexPanel { /** Update caption for given widget */ public void updateCaption(ComponentConnector paintable) { Widget widget = paintable.getWidget(); + if (widget.getParent() != this) { + // Widget has not been added because the location was not found + return; + } VCaptionWrapper wrapper = childWidgetToCaptionWrapper.get(widget); if (VCaption.isNeeded(paintable.getState())) { if (wrapper == null) { diff --git a/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java b/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java index cde1f1af0f..abbb0ef60b 100644 --- a/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java @@ -15,6 +15,8 @@ */ package com.vaadin.client.ui.customlayout; +import java.util.logging.Logger; + import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConnection; @@ -111,6 +113,9 @@ public class CustomLayoutConnector extends AbstractLayoutConnector implements getWidget().setWidget(child.getWidget(), location); } catch (final IllegalArgumentException e) { // If no location is found, this component is not visible + getLogger().warning( + "Child not rendered as no slot with id '" + location + + "' has been defined"); } } for (ComponentConnector oldChild : event.getOldChildren()) { @@ -147,4 +152,8 @@ public class CustomLayoutConnector extends AbstractLayoutConnector implements // Not interested in anything from the UIDL - just implementing the // interface to avoid some warning (#8688) } + + private static Logger getLogger() { + return Logger.getLogger(CustomLayoutConnector.class.getName()); + } } diff --git a/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithMissingSlot.java b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithMissingSlot.java new file mode 100644 index 0000000000..91b5dcc0ea --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithMissingSlot.java @@ -0,0 +1,59 @@ +/* + * 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 java.io.ByteArrayInputStream; +import java.io.IOException; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.CustomLayout; +import com.vaadin.ui.TextField; + +public class CustomLayoutWithMissingSlot extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + CustomLayout cl; + try { + cl = new CustomLayout( + new ByteArrayInputStream( + "<div>First: <div location='first'></div><p>Second: <div location='second'></div><p>" + .getBytes("UTF-8"))); + cl.addComponent(new TextField("This should be visible"), "first"); + Button button = new Button( + "This button is visible, together with one label"); + button.addClickListener(new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + log("Button clicked"); + } + }); + cl.addComponent(button, "second"); + cl.addComponent(new TextField( + "This won't be as the slot is missing"), "third"); + + addComponent(cl); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithMissingSlotTest.java b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithMissingSlotTest.java new file mode 100644 index 0000000000..d47a100a93 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutWithMissingSlotTest.java @@ -0,0 +1,38 @@ +/* + * 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 java.util.logging.Level; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class CustomLayoutWithMissingSlotTest extends SingleBrowserTest { + + @Test + public void ensureRenderedWithoutErrors() { + setDebug(true); + openTestURL(); + Assert.assertEquals("", getLogRow(0).trim()); + $(ButtonElement.class).first().click(); + assertNoDebugMessage(Level.SEVERE); + Assert.assertEquals("1. Button clicked", getLogRow(0)); + } + +} diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index 48f99e5057..ddf90b080b 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.List; import java.util.NoSuchElementException; import java.util.Set; +import java.util.logging.Level; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -35,6 +36,7 @@ import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicHttpEntityEnclosingRequest; +import org.junit.Assert; import org.junit.Rule; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -823,6 +825,22 @@ public abstract class AbstractTB3Test extends ParallelTest { return findElement(By.xpath("//button[@title='Debug message log']")); } + protected void assertNoDebugMessage(Level level) { + // class="v-debugwindow-row Level.getName()" + List<WebElement> logElements = driver + .findElements(By.xpath(String + .format("//div[@class='v-debugwindow-row %s']/span[@class='v-debugwindow-message']", + level.getName()))); + if (!logElements.isEmpty()) { + String logRows = ""; + for (WebElement e : logElements) { + logRows += "\n" + e.getText(); + } + Assert.fail("Found debug messages with level " + level.getName() + + ": " + logRows); + } + } + /** * Should the "require window focus" be enabled for Internet Explorer. * RequireWindowFocus makes tests more stable but seems to be broken with |