You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pe...@apache.org on 2011/03/24 21:07:44 UTC
svn commit: r1085111 - in /wicket/trunk/wicket-core/src:
main/java/org/apache/wicket/ main/java/org/apache/wicket/markup/html/
main/java/org/apache/wicket/markup/parser/filter/
test/java/org/apache/wicket/markup/html/
Author: pedro
Date: Thu Mar 24 20:07:44 2011
New Revision: 1085111
URL: http://svn.apache.org/viewvc?rev=1085111&view=rev
Log:
- improving the EnclosureHandler to assign unique ids to enclosure components
- preventing TransparentWebMarkupContainer from resolve its parent's children components to their grandchildren when TWC parent will render them
Issue: WICKET-3512
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage1.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage1.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage2.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage2.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage3.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage3.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage_expected.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/TransparentWebMarkupContainerTest.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Page.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/TransparentWebMarkupContainer.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/EnclosureHandler.java
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Page.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Page.java?rev=1085111&r1=1085110&r2=1085111&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Page.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Page.java Thu Mar 24 20:07:44 2011
@@ -1155,4 +1155,15 @@ public abstract class Page extends Marku
setFreezePageId(false);
}
}
+
+ /**
+ * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL.
+ *
+ * @param component
+ * @return if this component was render in this page
+ */
+ public final boolean wasRendered(Component component)
+ {
+ return renderedComponents != null && renderedComponents.contains(component);
+ }
}
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/TransparentWebMarkupContainer.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/TransparentWebMarkupContainer.java?rev=1085111&r1=1085110&r2=1085111&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/TransparentWebMarkupContainer.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/TransparentWebMarkupContainer.java Thu Mar 24 20:07:44 2011
@@ -47,6 +47,16 @@ public class TransparentWebMarkupContain
*/
public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag)
{
- return getParent().get(tag.getId());
+ Component resolvedComponent = getParent().get(tag.getId());
+ if (resolvedComponent != null && getPage().wasRendered(resolvedComponent))
+ {
+ /*
+ * Means that parent container has an associated homonymous tag to this grandchildren
+ * tag in markup. The parent container wants render it and it should be not resolved to
+ * their grandchildren.
+ */
+ return null;
+ }
+ return resolvedComponent;
}
}
\ No newline at end of file
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/EnclosureHandler.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/EnclosureHandler.java?rev=1085111&r1=1085110&r2=1085111&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/EnclosureHandler.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/EnclosureHandler.java Thu Mar 24 20:07:44 2011
@@ -156,7 +156,8 @@ public final class EnclosureHandler exte
if ((tag instanceof WicketTag) && ((WicketTag)tag).isEnclosureTag())
{
// Yes, we handled the tag
- return new Enclosure(tag.getId(), tag.getAttribute(EnclosureHandler.CHILD_ATTRIBUTE));
+ return new Enclosure(tag.getId() + container.getPage().getAutoIndex(),
+ tag.getAttribute(EnclosureHandler.CHILD_ATTRIBUTE));
}
// We were not able to handle the tag
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage1.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage1.html?rev=1085111&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage1.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage1.html Thu Mar 24 20:07:44 2011
@@ -0,0 +1,9 @@
+<html>
+<head>
+<title>title</title>
+</head>
+<body>
+<div wicket:id="test1"></div>
+<wicket:child></wicket:child>
+</body>
+</html>
\ No newline at end of file
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage1.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage1.java?rev=1085111&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage1.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage1.java Thu Mar 24 20:07:44 2011
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+/** */
+public class MarkupInheritanceResolverTestPage1 extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ /** */
+ public MarkupInheritanceResolverTestPage1()
+ {
+ add(new Label("test1", "test1"));
+ }
+}
\ No newline at end of file
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage2.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage2.html?rev=1085111&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage2.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage2.html Thu Mar 24 20:07:44 2011
@@ -0,0 +1,6 @@
+<wicket:extend>
+ <wicket:enclosure child="test2">
+ <div wicket:id="test2"></div>
+ </wicket:enclosure>
+ <wicket:child></wicket:child>
+</wicket:extend>
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage2.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage2.java?rev=1085111&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage2.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage2.java Thu Mar 24 20:07:44 2011
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+import org.apache.wicket.markup.html.basic.Label;
+
+/** */
+public class MarkupInheritanceResolverTestPage2 extends MarkupInheritanceResolverTestPage1
+{
+ private static final long serialVersionUID = 1L;
+
+ /** */
+ public MarkupInheritanceResolverTestPage2()
+ {
+ add(new Label("test2", "test2"));
+ }
+
+}
\ No newline at end of file
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage3.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage3.html?rev=1085111&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage3.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage3.html Thu Mar 24 20:07:44 2011
@@ -0,0 +1,5 @@
+<wicket:extend>
+ <wicket:enclosure child="test3">
+ <div wicket:id="test3"></div>
+ </wicket:enclosure>
+</wicket:extend>
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage3.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage3.java?rev=1085111&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage3.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage3.java Thu Mar 24 20:07:44 2011
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+import org.apache.wicket.markup.html.basic.Label;
+
+/** */
+public class MarkupInheritanceResolverTestPage3 extends MarkupInheritanceResolverTestPage2
+{
+ private static final long serialVersionUID = 1L;
+
+ /** */
+ public MarkupInheritanceResolverTestPage3()
+ {
+ add(new Label("test3", "test3"));
+ }
+
+}
\ No newline at end of file
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage_expected.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage_expected.html?rev=1085111&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage_expected.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/MarkupInheritanceResolverTestPage_expected.html Thu Mar 24 20:07:44 2011
@@ -0,0 +1,18 @@
+<html>
+<head>
+<title>title</title>
+</head>
+<body>
+<div wicket:id="test1">test1</div>
+<wicket:child><wicket:extend>
+ <wicket:enclosure child="test2">
+ <div wicket:id="test2">test2</div>
+ </wicket:enclosure>
+ <wicket:child><wicket:extend>
+ <wicket:enclosure child="test3">
+ <div wicket:id="test3">test3</div>
+ </wicket:enclosure>
+</wicket:extend></wicket:child>
+</wicket:extend></wicket:child>
+</body>
+</html>
\ No newline at end of file
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/TransparentWebMarkupContainerTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/TransparentWebMarkupContainerTest.java?rev=1085111&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/TransparentWebMarkupContainerTest.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/TransparentWebMarkupContainerTest.java Thu Mar 24 20:07:44 2011
@@ -0,0 +1,177 @@
+/*
+ * 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;
+
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.markup.IMarkupResourceStreamProvider;
+import org.apache.wicket.markup.MarkupException;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.border.Border;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.StringResourceStream;
+
+/**
+ * @author Pedro Santos
+ */
+public class TransparentWebMarkupContainerTest extends WicketTestCase
+{
+
+ /**
+ * WICKET-3512
+ *
+ * @throws Exception
+ */
+ public void testMarkupInheritanceResolver() throws Exception
+ {
+ executeTest(MarkupInheritanceResolverTestPage3.class,
+ "MarkupInheritanceResolverTestPage_expected.html");
+ }
+
+ /**
+ *
+ */
+ public void testUnableToFindComponents()
+ {
+ try
+ {
+ tester.startPage(TestPage.class);
+ fail();
+ }
+ catch (MarkupException e)
+ {
+ assertTrue(e.getMessage(),
+ e.getMessage().contains("Unable to find component with id 'c1'"));
+ }
+ }
+
+ /**
+ * Test if the render is OK even if users define its own component with the same id
+ * WicketTagIdentifier is generation for internal components.
+ */
+ public void testUsingGeneratedWicketIdAreSafe1()
+ {
+ tester.startPage(TestPage2.class);
+ assertTrue(tester.getLastResponseAsString().contains("test_message"));
+
+ }
+
+ /**
+ * Same test in different scenario
+ */
+ public void testUsingGeneratedWicketIdAreSafe2()
+ {
+ tester.startPage(TestPage3.class);
+ String expected = tester.getApplication()
+ .getResourceSettings()
+ .getLocalizer()
+ .getString("null", null);
+ assertTrue(tester.getLastResponseAsString().contains(expected));
+ }
+
+ /** */
+ public static class TestPage extends WebPage implements IMarkupResourceStreamProvider
+ {
+ private static final long serialVersionUID = 1L;
+
+ /** */
+ public TestPage()
+ {
+ add(new TestBorder("border"));
+ }
+
+ public IResourceStream getMarkupResourceStream(MarkupContainer container,
+ Class<?> containerClass)
+ {
+ return new StringResourceStream("" + //
+ "<html><body>" + //
+ " <div wicket:id=\"border\">" + //
+ " <div wicket:id=\"c1\"></div>" + // component is only at the markup
+ " </div>" + //
+ "</body></html>");
+ }
+ }
+ private static class TestBorder extends Border implements IMarkupResourceStreamProvider
+ {
+ private static final long serialVersionUID = 1L;
+
+ private TestBorder(String id)
+ {
+ super(id);
+ addToBorder(new Label("c1", "some border title"));
+ }
+
+ public IResourceStream getMarkupResourceStream(MarkupContainer container,
+ Class<?> containerClass)
+ {
+ return new StringResourceStream(
+ "<wicket:border><div wicket:id=\"c1\"></div><wicket:body /></wicket:border>");
+ }
+ }
+
+ /** */
+ public static class TestPage2 extends WebPage implements IMarkupResourceStreamProvider
+ {
+ private static final long serialVersionUID = 1L;
+
+ /** */
+ public TestPage2()
+ {
+ add(new Label("_wicket_enclosure"));
+ add(new TransparentWebMarkupContainer("container").add(new Label("msg", "test_message")));
+ }
+
+ public IResourceStream getMarkupResourceStream(MarkupContainer container,
+ Class<?> containerClass)
+ {
+ return new StringResourceStream("" + //
+ "<html><body>" + //
+ " <div wicket:id=\"_wicket_enclosure\"></div>" + //
+ " <div wicket:id=\"container\">" + //
+ " <wicket:enclosure child=\"msg\">" + //
+ " <span wicket:id=\"msg\"></span>" + //
+ " </wicket:enclosure>" + //
+ " </div>" + //
+ "</body></html>");
+ }
+ }
+
+ /** */
+ public static class TestPage3 extends WebPage implements IMarkupResourceStreamProvider
+ {
+ private static final long serialVersionUID = 1L;
+
+ /** */
+ public TestPage3()
+ {
+ add(new WebComponent("_wicket_message"));
+ add(new TransparentWebMarkupContainer("container"));
+ }
+
+ public IResourceStream getMarkupResourceStream(MarkupContainer container,
+ Class<?> containerClass)
+ {
+ return new StringResourceStream("" + //
+ "<html><body>" + //
+ " <div wicket:id=\"_wicket_message\"></div>" + //
+ " <div wicket:id=\"container\">" + //
+ " <wicket:message key=\"null\" />" + //
+ " </div>" + //
+ "</body></html>");
+ }
+ }
+}