Author: dashorst
Date: Wed Aug 24 13:26:59 2011
New Revision: 1161092
URL: http://svn.apache.org/viewvc?rev=1161092&view=rev
Log:
WICKET-3989 fixed by letting the sourcing strategies also look for transparent
containers
Issue: WICKET-3989
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/BasePanel.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/BasePanel.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/HomePage.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/HomePage.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/Issue3989Test.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AbstractMarkupSourcingStrategy.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AssociatedMarkupSourcingStrategy.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/DefaultMarkupSourcingStrategy.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/IMarkupSourcingStrategy.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AbstractMarkupSourcingStrategy.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AbstractMarkupSourcingStrategy.java?rev=1161092&r1=1161091&r2=1161092&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AbstractMarkupSourcingStrategy.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AbstractMarkupSourcingStrategy.java
Wed Aug 24 13:26:59 2011
@@ -24,6 +24,7 @@ import org.apache.wicket.markup.MarkupEx
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.internal.HtmlHeaderContainer;
import org.apache.wicket.markup.parser.XmlTag.TagType;
+import org.apache.wicket.markup.resolver.IComponentResolver;
/**
* Implements boilerplate as needed by many markup sourcing strategies.
@@ -42,6 +43,40 @@ public abstract class AbstractMarkupSour
public abstract IMarkupFragment getMarkup(final MarkupContainer
container, final Component child);
/**
+ * If the child has not been directly added to the container, but via a
+ * TransparentWebMarkupContainer, then we are in trouble. In general
Wicket iterates over the
+ * markup elements and searches for associated components, not the
other way around. Because of
+ * TransparentWebMarkupContainer (or more generally resolvers), there
is no "synchronous" search
+ * possible.
+ *
+ * @param container
+ * the parent container.
+ * @param child
+ * The component to find the markup for.
+ * @return the markup fragment for the child, or {@code null}.
+ */
+ protected IMarkupFragment searchMarkupInTransparentResolvers(final
MarkupContainer container,
+ final Component child)
+ {
+ IMarkupFragment markup = null;
+
+ for (Component ch : container)
+ {
+ if ((ch != child) && (ch instanceof MarkupContainer) &&
+ (ch instanceof IComponentResolver))
+ {
+ markup = ((MarkupContainer)ch).getMarkup(child);
+ if (markup != null)
+ {
+ break;
+ }
+ }
+ }
+
+ return markup;
+ }
+
+ /**
* Make sure we open up open-close tags to open-body-close
*/
public void onComponentTag(final Component component, final
ComponentTag tag)
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AssociatedMarkupSourcingStrategy.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AssociatedMarkupSourcingStrategy.java?rev=1161092&r1=1161091&r2=1161092&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AssociatedMarkupSourcingStrategy.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/AssociatedMarkupSourcingStrategy.java
Wed Aug 24 13:26:59 2011
@@ -119,6 +119,12 @@ public abstract class AssociatedMarkupSo
return associatedMarkup;
}
+ associatedMarkup = searchMarkupInTransparentResolvers(parent,
child);
+ if (associatedMarkup != null)
+ {
+ return associatedMarkup;
+ }
+
return findMarkupInAssociatedFileHeader(parent, child);
}
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/DefaultMarkupSourcingStrategy.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/DefaultMarkupSourcingStrategy.java?rev=1161092&r1=1161091&r2=1161092&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/DefaultMarkupSourcingStrategy.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/DefaultMarkupSourcingStrategy.java
Wed Aug 24 13:26:59 2011
@@ -23,7 +23,6 @@ import org.apache.wicket.markup.IMarkupF
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.internal.HtmlHeaderContainer;
import org.apache.wicket.markup.html.list.AbstractItem;
-import org.apache.wicket.markup.resolver.IComponentResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,7 +31,7 @@ import org.slf4j.LoggerFactory;
*
* @author Juergen Donnerstag
*/
-public final class DefaultMarkupSourcingStrategy implements
IMarkupSourcingStrategy
+public final class DefaultMarkupSourcingStrategy extends
AbstractMarkupSourcingStrategy
{
/** Log for reporting. */
private static final Logger log =
LoggerFactory.getLogger(DefaultMarkupSourcingStrategy.class);
@@ -58,6 +57,7 @@ public final class DefaultMarkupSourcing
/**
* Nothing to add to the response by default
*/
+ @Override
public void onComponentTag(final Component component, final
ComponentTag tag)
{
}
@@ -65,6 +65,7 @@ public final class DefaultMarkupSourcing
/**
* Invoke the component's onComponentTagBody().
*/
+ @Override
public void onComponentTagBody(final Component component, final
MarkupStream markupStream,
final ComponentTag openTag)
{
@@ -74,6 +75,7 @@ public final class DefaultMarkupSourcing
/**
* Get the markup for the child component, which is assumed to be a
child of 'container'.
*/
+ @Override
public IMarkupFragment getMarkup(final MarkupContainer container, final
Component child)
{
// If the sourcing strategy did not provide one, than ask the
component.
@@ -96,22 +98,10 @@ public final class DefaultMarkupSourcing
return markup;
}
- // If the child has not been directly added to the container,
but via a
- // TransparentWebMarkupContainer, then we are in trouble. In
general Wicket iterates over
- // the markup elements and searches for associated components,
not the other way around.
- // Because of TransparentWebMarkupContainer (or more generally
resolvers), there is no
- // "synchronous" search possible.
- for (Component ch : container)
+ markup = searchMarkupInTransparentResolvers(container, child);
+ if (markup != null)
{
- if ((ch != child) && (ch instanceof MarkupContainer) &&
- (ch instanceof IComponentResolver))
- {
- markup = ((MarkupContainer)ch).getMarkup(child);
- if (markup != null)
- {
- return markup;
- }
- }
+ return markup;
}
// This is to make migration for Items from 1.4 to 1.5 more easy
@@ -156,6 +146,7 @@ public final class DefaultMarkupSourcing
/**
* Empty: nothing will be added to the header by default
*/
+ @Override
public void renderHead(final Component component, HtmlHeaderContainer
container)
{
}
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/IMarkupSourcingStrategy.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/IMarkupSourcingStrategy.java?rev=1161092&r1=1161091&r2=1161092&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/IMarkupSourcingStrategy.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/IMarkupSourcingStrategy.java
Wed Aug 24 13:26:59 2011
@@ -22,6 +22,7 @@ import org.apache.wicket.markup.Componen
import org.apache.wicket.markup.IMarkupFragment;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.internal.HtmlHeaderContainer;
+import org.apache.wicket.markup.resolver.IComponentResolver;
/**
* Markup sourcing strategies determine whether a Component behaves like a
"Panel" pulling its
@@ -79,10 +80,11 @@ public interface IMarkupSourcingStrategy
* @see MarkupContainer#getMarkup(Component)
*
* @param container
- * The parent containing the child. (@TODO Is container ever
!= child.getParent()??)
+ * The parent containing the child. This is not the direct
parent, transparent
+ * component {@link IComponentResolver resolver} may be in
the hierarchy between.
* @param child
* The component to find the markup for.
- * @return markup fragment
+ * @return the markup fragment for the child, or {@code null}.
*/
IMarkupFragment getMarkup(final MarkupContainer container, final
Component child);
}
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/BasePanel.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/BasePanel.html?rev=1161092&view=auto
==============================================================================
---
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/BasePanel.html
(added)
+++
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/BasePanel.html
Wed Aug 24 13:26:59 2011
@@ -0,0 +1,12 @@
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+</head>
+<body>
+<wicket:panel>
+ <div wicket:id="transparent">
+ <div wicket:id="innerpanel"></div>
+ <a href="#" wicket:id="link">Click here to crash</a>
+ </div>
+</wicket:panel>
+</body>
+</html>
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/BasePanel.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/BasePanel.java?rev=1161092&view=auto
==============================================================================
---
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/BasePanel.java
(added)
+++
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/BasePanel.java
Wed Aug 24 13:26:59 2011
@@ -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.markup.resolver.issue3989;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.TransparentWebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.Panel;
+
+@SuppressWarnings("javadoc")
+public class BasePanel extends Panel
+{
+ private static final long serialVersionUID = 1L;
+
+ public BasePanel(String id)
+ {
+ super(id);
+ add(new TransparentWebMarkupContainer("transparent"));
+ final Label label = new Label("innerpanel", "Test");
+ label.setOutputMarkupId(true);
+ add(label);
+
+ add(new AjaxLink<Void>("link")
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onClick(AjaxRequestTarget target)
+ {
+ target.add(label);
+ }
+ });
+ }
+}
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/HomePage.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/HomePage.html?rev=1161092&view=auto
==============================================================================
---
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/HomePage.html
(added)
+++
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/HomePage.html
Wed Aug 24 13:26:59 2011
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org">
+ <head>
+ <meta charset="utf-8" />
+ <title>Apache Wicket Quickstart</title>
+ <link
href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:regular,bold'
rel='stylesheet' type='text/css' />
+ <link rel="stylesheet" href="style.css" type="text/css"
media="screen" title="Stylesheet" />
+ </head>
+ <body>
+ <div id="hd">
+ <div id="logo">
+ <img src="logo.png" width="50px" height="50px"
alt="Wicket Logo" />
+ <h1>Apache Wicket</h1>
+ </div>
+ </div>
+ <div id="bd">
+ <p>
+ Please mention the correct Wicket version:
<wicket:container wicket:id="version">1.5-SNAPSHOT</wicket:container>.
+ </p>
+ </div>
+ <div wicket:id="panel"></div>
+ <div id="ft">
+ </div>
+ </body>
+</html>
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/HomePage.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/HomePage.java?rev=1161092&view=auto
==============================================================================
---
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/HomePage.java
(added)
+++
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/HomePage.java
Wed Aug 24 13:26:59 2011
@@ -0,0 +1,33 @@
+/*
+ * 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.issue3989;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+@SuppressWarnings("javadoc")
+public class HomePage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ public HomePage(final PageParameters parameters)
+ {
+ add(new Label("version",
getApplication().getFrameworkSettings().getVersion()));
+ add(new BasePanel("panel"));
+ }
+}
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/Issue3989Test.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/Issue3989Test.java?rev=1161092&view=auto
==============================================================================
---
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/Issue3989Test.java
(added)
+++
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/resolver/issue3989/Issue3989Test.java
Wed Aug 24 13:26:59 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.issue3989;
+
+import org.apache.wicket.util.tester.WicketTester;
+import org.junit.Test;
+
+/**
+ * When the {@link org.apache.wicket.Component#markup markup of a component}
has been reset at the
+ * end of the request, and the component's markup was resolved by a
+ * {@code TransparentWebMarkupContainer}, it will fail when being re-rendered
in an Ajax request.
+ * The cause is that the {@code PanelMarkupSourcingStrategy} fails to look for
markup in
+ * {@code IComponentResolver}s like {@code TransparentWebMarkupContainer}.
+ */
+public class Issue3989Test
+{
+ /**
+ * This will fail unless the markup sourcing strategies look for the
label {@code innerpanel} in
+ * the transparent markup container.
+ */
+ @Test
+ public void ajaxRenderOfTransparentlyResolvedLabel()
+ {
+ WicketTester tester = new WicketTester();
+ tester.startPage(HomePage.class);
+ tester.assertRenderedPage(HomePage.class);
+ tester.clickLink("panel:link");
+ tester.assertComponentOnAjaxResponse("panel:innerpanel");
+ }
+}