You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2014/05/26 21:43:11 UTC
git commit: WICKET-5569 Unable to find markup for children of deeply
nested IComponentResolvers during Ajax response
Repository: wicket
Updated Branches:
refs/heads/wicket-6.x bc62f8cca -> e40ae9188
WICKET-5569 Unable to find markup for children of deeply nested IComponentResolvers during Ajax response
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/e40ae918
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/e40ae918
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/e40ae918
Branch: refs/heads/wicket-6.x
Commit: e40ae9188ca3810eab77c1ed80efa6f05203b2ca
Parents: bc62f8c
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon May 26 21:40:06 2014 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon May 26 21:40:06 2014 +0200
----------------------------------------------------------------------
.../panel/AbstractMarkupSourcingStrategy.java | 39 +++++---
.../markup/resolver/issue5569/HomePage.html | 40 +++++++++
.../markup/resolver/issue5569/HomePage.java | 93 ++++++++++++++++++++
.../resolver/issue5569/Issue5569Test.java | 34 +++++++
4 files changed, 195 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/e40ae918/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AbstractMarkupSourcingStrategy.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AbstractMarkupSourcingStrategy.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AbstractMarkupSourcingStrategy.java
index c7fe735..cbddd25 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AbstractMarkupSourcingStrategy.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AbstractMarkupSourcingStrategy.java
@@ -26,6 +26,8 @@ import org.apache.wicket.markup.html.internal.HtmlHeaderContainer;
import org.apache.wicket.markup.parser.XmlTag.TagType;
import org.apache.wicket.markup.resolver.IComponentResolver;
import org.apache.wicket.util.lang.Classes;
+import org.apache.wicket.util.visit.IVisit;
+import org.apache.wicket.util.visit.IVisitor;
/**
* Implements boilerplate as needed by many markup sourcing strategies.
@@ -60,22 +62,37 @@ public abstract class AbstractMarkupSourcingStrategy implements IMarkupSourcingS
protected IMarkupFragment searchMarkupInTransparentResolvers(final MarkupContainer container,
final Component child)
{
- IMarkupFragment markup = null;
-
- for (Component ch : container)
+ return container.visitChildren(MarkupContainer.class, new IVisitor<MarkupContainer, IMarkupFragment>()
{
- if ((ch != child) && (ch instanceof MarkupContainer) &&
- (ch instanceof IComponentResolver))
+ @Override
+ public void component(MarkupContainer resolvingContainer, IVisit<IMarkupFragment> visit)
{
- markup = ((MarkupContainer)ch).getMarkup(child);
- if (markup != null)
+ if (resolvingContainer instanceof IComponentResolver)
{
- break;
+ IMarkupFragment childMarkup = resolvingContainer.getMarkup(child);
+
+ if (childMarkup != null && childMarkup.size() > 0)
+ {
+ IComponentResolver componentResolver = (IComponentResolver)resolvingContainer;
+
+ MarkupStream stream = new MarkupStream(childMarkup);
+
+ ComponentTag tag = stream.getTag();
+
+ Component resolvedComponent = resolvingContainer.get(tag.getId());
+ if (resolvedComponent == null)
+ {
+ resolvedComponent = componentResolver.resolve(resolvingContainer, stream, tag);
+ }
+
+ if (child == resolvedComponent)
+ {
+ visit.stop(childMarkup);
+ }
+ }
}
}
- }
-
- return markup;
+ });
}
/**
http://git-wip-us.apache.org/repos/asf/wicket/blob/e40ae918/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/HomePage.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/HomePage.html b/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/HomePage.html
new file mode 100644
index 0000000..86f11ae
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/HomePage.html
@@ -0,0 +1,40 @@
+<html>
+ <head>
+ <title>WICKET-5569 Test</title>
+ </head>
+ <body>
+
+ <a wicket:id="link">link</a>
+
+ <!--
+ mc1 is a TransparentWebMarkupContainer. This will contain a component called with id "special",
+ but importantly, this is NOT the "special" that should be added to the ajax response.
+ -->
+ <div wicket:id="mc1">
+ <div wicket:id="special">
+ WRONG_SPECIAL
+ </div>
+ </div>
+
+ <!--
+ A normal WebMarkupContainer so that we remove the chain of component resolvers so as to demonstrate
+ the problem.
+ -->
+ <div wicket:id="mc2">
+
+ <!--
+ A component resolving markup container that resolves from the page.
+ -->
+ <div wicket:id="mc3">
+
+ <!--
+ This is the "special" that the Ajax response must get.
+ -->
+ <div wicket:id="special">
+ CORRECT_SPECIAL
+ </div>
+
+ </div>
+ </div>
+ </body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/e40ae918/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/HomePage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/HomePage.java b/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/HomePage.java
new file mode 100644
index 0000000..84eafac
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/HomePage.java
@@ -0,0 +1,93 @@
+/*
+ * 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.resolver.issue5569;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.markup.html.TransparentWebMarkupContainer;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.resolver.IComponentResolver;
+
+public class HomePage extends WebPage
+{
+ @Override
+ protected void onInitialize()
+ {
+ super.onInitialize();
+
+ add(new AjaxLink<Void>("link")
+ {
+ @Override
+ public void onClick(AjaxRequestTarget target)
+ {
+ target.add(getPage().get("special"));
+ }
+ });
+
+ WebMarkupContainer mc1 = new TransparentWebMarkupContainer("mc1");
+
+ add(mc1);
+
+ mc1.add(new WebMarkupContainer("special"));
+
+ WebMarkupContainer mc2 = new WebMarkupContainer("mc2");
+
+ add(mc2);
+
+ WebMarkupContainer mc3 = new ComponentResolvingWebMarkupContainer("mc3", HomePage.this);
+
+ mc2.add(mc3);
+
+ add(new WebMarkupContainer("special").setOutputMarkupId(true));
+ }
+
+ private static class ComponentResolvingWebMarkupContainer
+ extends WebMarkupContainer
+ implements IComponentResolver
+ {
+ private final MarkupContainer resolveTarget;
+
+ public ComponentResolvingWebMarkupContainer(String id, MarkupContainer resolveTarget)
+ {
+ super(id);
+ this.resolveTarget = resolveTarget;
+ }
+
+ @Override
+ public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag)
+ {
+ Component c = resolveTarget.get(tag.getId());
+
+ if (c == null && resolveTarget instanceof IComponentResolver)
+ {
+ c = ((IComponentResolver)resolveTarget).resolve(container, markupStream, tag);
+ }
+
+ if (c != null && getPage().wasRendered(c))
+ {
+ return null;
+ }
+
+ return c;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/e40ae918/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/Issue5569Test.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/Issue5569Test.java b/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/Issue5569Test.java
new file mode 100644
index 0000000..f34b216
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue5569/Issue5569Test.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.resolver.issue5569;
+
+import org.apache.wicket.WicketTestCase;
+import org.junit.Test;
+
+public class Issue5569Test extends WicketTestCase
+{
+ @Test
+ public void testIssue5569()
+ {
+ tester.startPage(HomePage.class);
+ tester.assertRenderedPage(HomePage.class);
+ tester.clickLink("link");
+ tester.assertComponentOnAjaxResponse("special");
+ tester.assertContainsNot("WRONG_SPECIAL");
+ tester.assertContains("CORRECT_SPECIAL");
+ }
+}