Repository: wicket Updated Branches: refs/heads/wicket-7.x 529375ee1 -> 8c43b38a4
WICKET-6185 Border body not reachable for visitors Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/8c43b38a Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/8c43b38a Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/8c43b38a Branch: refs/heads/wicket-7.x Commit: 8c43b38a43efff07b22cc87ffa6946d7d88de379 Parents: 529375e Author: Andrea Del Bene <[email protected]> Authored: Wed Jun 22 18:36:13 2016 +0200 Committer: Andrea Del Bene <[email protected]> Committed: Wed Jun 22 18:36:13 2016 +0200 ---------------------------------------------------------------------- .../org/apache/wicket/ChildToDequeueType.java | 49 ++++++++++++++++++++ .../java/org/apache/wicket/MarkupContainer.java | 27 ++++++----- .../wicket/markup/html/border/Border.java | 34 ++++++++++++-- .../parser/filter/WicketTagIdentifier.java | 4 +- .../html/border/BorderWithNestedBody.html | 30 ++++++++++++ .../html/border/BorderWithNestedBody.java | 34 ++++++++++++++ .../markup/html/border/ComponentBorderTest.java | 10 ++++ 7 files changed, 172 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/8c43b38a/wicket-core/src/main/java/org/apache/wicket/ChildToDequeueType.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ChildToDequeueType.java b/wicket-core/src/main/java/org/apache/wicket/ChildToDequeueType.java new file mode 100644 index 0000000..29cfdfe --- /dev/null +++ b/wicket-core/src/main/java/org/apache/wicket/ChildToDequeueType.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.wicket; + +import org.apache.wicket.markup.html.border.Border; + +public enum ChildToDequeueType +{ + NULL, GENERIC_COMPONENT, MARKUP_CONTAINER, BORDER, QUEUE_REGION; + + public static ChildToDequeueType fromChild(Component child) + { + if (child == null) + { + return NULL; + } + + if (child instanceof Border) + { + return BORDER; + } + + if (child instanceof IQueueRegion) + { + return QUEUE_REGION; + } + + if (child instanceof MarkupContainer) + { + return MARKUP_CONTAINER; + } + + return GENERIC_COMPONENT; + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/8c43b38a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java index 798cc67..791ae73 100644 --- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java +++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java @@ -2144,24 +2144,29 @@ public abstract class MarkupContainer extends Component implements Iterable<Comp */ private void dequeueChild(Component child, ComponentTag tag, DequeueContext dequeue) { - if (child == null) - { - // could not dequeue, or is a dequeue container - dequeue.skipToCloseTag(); - } - else if (child instanceof IQueueRegion) + ChildToDequeueType childType = ChildToDequeueType.fromChild(child); + + if (childType == ChildToDequeueType.QUEUE_REGION || + childType == ChildToDequeueType.BORDER) { - ((IQueueRegion)child).dequeue(); - dequeue.skipToCloseTag(); + ((IQueueRegion)child).dequeue(); } - else if (child instanceof MarkupContainer) + + if (childType == ChildToDequeueType.MARKUP_CONTAINER || + childType == ChildToDequeueType.BORDER) { // propagate dequeuing to containers MarkupContainer childContainer = (MarkupContainer)child; - + dequeue.pushContainer(childContainer); childContainer.dequeue(dequeue); - dequeue.popContainer(); + dequeue.popContainer(); + } + + if (childType == ChildToDequeueType.NULL || + childType == ChildToDequeueType.QUEUE_REGION) + { + dequeue.skipToCloseTag(); } // pull the close tag off http://git-wip-us.apache.org/repos/asf/wicket/blob/8c43b38a/wicket-core/src/main/java/org/apache/wicket/markup/html/border/Border.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/border/Border.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/border/Border.java index 5ef0468..3104b23 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/border/Border.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/border/Border.java @@ -22,6 +22,7 @@ import org.apache.wicket.DequeueTagAction; import org.apache.wicket.IQueueRegion; import org.apache.wicket.MarkupContainer; import org.apache.wicket.markup.ComponentTag; +import org.apache.wicket.markup.ContainerInfo; import org.apache.wicket.markup.IMarkupFragment; import org.apache.wicket.markup.MarkupElement; import org.apache.wicket.markup.MarkupException; @@ -34,6 +35,7 @@ import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.panel.BorderMarkupSourcingStrategy; import org.apache.wicket.markup.html.panel.IMarkupSourcingStrategy; import org.apache.wicket.markup.parser.XmlTag.TagType; +import org.apache.wicket.markup.parser.filter.WicketTagIdentifier; import org.apache.wicket.markup.resolver.IComponentResolver; import org.apache.wicket.model.IModel; import org.apache.wicket.util.lang.Args; @@ -316,6 +318,13 @@ public abstract class Border extends WebMarkupContainer implements IComponentRes public Border addToBorder(final Component... children) { super.add(children); + + //if body has not been assigned yet, we queue it + if (body.getParent() == null) + { + dequeue(); + } + return this; } @@ -637,7 +646,7 @@ public abstract class Border extends WebMarkupContainer implements IComponentRes @Override protected DequeueTagAction canDequeueTag(ComponentTag tag) { - if ((tag instanceof WicketTag) && ((WicketTag)tag).isBodyTag()) + if (canDequeueBody(tag)) { return DequeueTagAction.DEQUEUE; } @@ -648,18 +657,35 @@ public abstract class Border extends WebMarkupContainer implements IComponentRes @Override public Component findComponentToDequeue(ComponentTag tag) { - if ((tag instanceof WicketTag) && ((WicketTag)tag).isBodyTag()) + if (canDequeueBody(tag)) { - return getBodyContainer(); + //synch the tag id with the one of the body component + tag.setId(body.getId()); + return body; } return super.findComponentToDequeue(tag); } + private boolean canDequeueBody(ComponentTag tag) + { + ContainerInfo containerInfo = (ContainerInfo)tag.getUserData( + WicketTagIdentifier.CONTAINER_INFO); + Class<?> containerClass = containerInfo != null ? + containerInfo.getContainerClass() : null; + + boolean isBodyTag = (tag instanceof WicketTag) && ((WicketTag)tag).isBodyTag(); + + //the body tag might belong to an outer body component + boolean isBorderBodyTag = containerClass == null || containerClass.equals(getClass()); + + return isBodyTag && isBorderBodyTag; + } + @Override protected void addDequeuedComponent(Component component, ComponentTag tag) { // components queued in border get dequeued into the border not into the body container - addToBorder(component); + super.add(component); } /** http://git-wip-us.apache.org/repos/asf/wicket/blob/8c43b38a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java index 2694508..99b7ee5 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java @@ -50,6 +50,7 @@ import org.apache.wicket.util.string.Strings; */ public final class WicketTagIdentifier extends AbstractMarkupFilter { + public static final String CONTAINER_INFO = "containerInfo"; /** List of well known wicket tag names */ private static final Set<String> WELL_KNOWN_TAG_NAMES = new HashSet<>(); /** List of raw wicket tag names */ @@ -121,8 +122,9 @@ public final class WicketTagIdentifier extends AbstractMarkupFilter { // Make it a Wicket component. tag.setId(namespace + "_" + tag.getName() + getRequestUniqueId()); + tag.setUserData(CONTAINER_INFO, getMarkupResourceStream().getContainerInfo()); tag.setModified(true); - + if (isRaw(tag)) { tag.setFlag(ComponentTag.RENDER_RAW, true); http://git-wip-us.apache.org/repos/asf/wicket/blob/8c43b38a/wicket-core/src/test/java/org/apache/wicket/markup/html/border/BorderWithNestedBody.html ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/border/BorderWithNestedBody.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/border/BorderWithNestedBody.html new file mode 100644 index 0000000..b7d3449 --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/border/BorderWithNestedBody.html @@ -0,0 +1,30 @@ +<!-- + ==================================================================== + 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. +--> +<!DOCTYPE html> +<html> +<head> +<meta charset="UTF-8"> +<title>Insert title here</title> +</head> +<body> + <wicket:border> + <div class="content"> + <div wicket:id="nestedBorder"> + <wicket:body/> + </div> + </div> + </wicket:border> +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/8c43b38a/wicket-core/src/test/java/org/apache/wicket/markup/html/border/BorderWithNestedBody.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/border/BorderWithNestedBody.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/border/BorderWithNestedBody.java new file mode 100644 index 0000000..b23c2e5 --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/border/BorderWithNestedBody.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.wicket.markup.html.border; + +public class BorderWithNestedBody extends Border +{ + + /** + * + */ + private static final long serialVersionUID = 3233023845189903488L; + + public BorderWithNestedBody(String id) + { + super(id); + + addToBorder(new BorderComponent1("nestedBorder")); + } + +} http://git-wip-us.apache.org/repos/asf/wicket/blob/8c43b38a/wicket-core/src/test/java/org/apache/wicket/markup/html/border/ComponentBorderTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/border/ComponentBorderTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/border/ComponentBorderTest.java index 7761a18..e3f38b8 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/border/ComponentBorderTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/border/ComponentBorderTest.java @@ -126,4 +126,14 @@ public class ComponentBorderTest extends WicketTestCase tester.startPage(BorderWithAutoLabelPage.class); tester.assertRenderedPage(BorderWithAutoLabelPage.class); } + + @Test + public void borderWithBodyInsideAnotherBody() throws Exception + { + Border borderTest = tester.startComponentInPage(new BorderWithNestedBody("test")); + Border nestedBorder = (Border)borderTest.get("nestedBorder"); + + assertNotNull(borderTest.getBodyContainer().getParent()); + assertNotNull(nestedBorder.getBodyContainer().getParent()); + } }
