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 2012/01/31 16:56:32 UTC

[1/2] git commit: WICKET-4361 Markup Inheritance & getVariation(): markup loading (and merging) order depends on whether the super constructor adds components or not.

Updated Branches:
  refs/heads/master 91ab43d24 -> 557e43527


WICKET-4361
Markup Inheritance & getVariation(): markup loading (and merging) order depends on whether the super constructor adds components or not.


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/557e4352
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/557e4352
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/557e4352

Branch: refs/heads/master
Commit: 557e43527a43dde43aa4e68d34a2a99bfabef210
Parents: 683c1b0
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Tue Jan 31 17:56:29 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Tue Jan 31 17:56:29 2012 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/wicket/Component.java |   11 ++-
 .../java/org/apache/wicket/MarkupContainer.java    |   43 -------
 .../org/apache/wicket/OnMarkupAttachedTest.java    |   97 +++++++++++++++
 3 files changed, 107 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/557e4352/wicket-core/src/main/java/org/apache/wicket/Component.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/Component.java b/wicket-core/src/main/java/org/apache/wicket/Component.java
index ce6274a..e80013c 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Component.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Component.java
@@ -737,7 +737,7 @@ public abstract class Component
 	 * 
 	 * @return false, if it was called the first time
 	 */
-	final boolean internalOnMarkupAttached()
+	private boolean internalOnMarkupAttached()
 	{
 		boolean rtn = getFlag(FLAG_MARKUP_ATTACHED);
 		if (rtn == false)
@@ -880,6 +880,15 @@ public abstract class Component
 	protected void onInitialize()
 	{
 		setRequestFlag(RFLAG_INITIALIZE_SUPER_CALL_VERIFIED, true);
+
+		try
+		{
+			internalOnMarkupAttached();
+		}
+		catch (WicketRuntimeException exception)
+		{
+			// ignore
+		}
 	}
 
 	/**

http://git-wip-us.apache.org/repos/asf/wicket/blob/557e4352/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 ed80d33..0c13dbe 100644
--- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
+++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
@@ -174,49 +174,6 @@ public abstract class MarkupContainer extends Component implements Iterable<Comp
 				throw new IllegalArgumentException(exceptionMessage("A child with id '" +
 					child.getId() + "' already exists"));
 			}
-
-			// One of the key pre-requisites to successfully load markup, is the availability of the
-			// file extension. Which in turn is part of MarkupType which by default requires the
-			// Page.
-			if (getMarkupType() != null)
-			{
-				// Check if the markup is available after the child has been added to the parent
-				try
-				{
-					// If not yet triggered, then do now (e.g. Pages)
-					if (getMarkup() != null)
-					{
-						internalOnMarkupAttached();
-					}
-
-					if (child.getMarkup() != null)
-					{
-						child.internalOnMarkupAttached();
-
-						// Tell all children of "component" as well
-						if (child instanceof MarkupContainer)
-						{
-							MarkupContainer container = (MarkupContainer)child;
-							container.visitChildren(new IVisitor<Component, Void>()
-							{
-								@Override
-								public void component(final Component component,
-									final IVisit<Void> visit)
-								{
-									if (component.internalOnMarkupAttached())
-									{
-										visit.dontGoDeeper();
-									}
-								}
-							});
-						}
-					}
-				}
-				catch (WicketRuntimeException exception)
-				{
-					// ignore
-				}
-			}
 		}
 		return this;
 	}

http://git-wip-us.apache.org/repos/asf/wicket/blob/557e4352/wicket-core/src/test/java/org/apache/wicket/OnMarkupAttachedTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/OnMarkupAttachedTest.java b/wicket-core/src/test/java/org/apache/wicket/OnMarkupAttachedTest.java
new file mode 100644
index 0000000..c0fb65a
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/OnMarkupAttachedTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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 java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.wicket.markup.IMarkupResourceStreamProvider;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.StringResourceStream;
+import org.junit.Test;
+
+/**
+ * Verifies that each Component's onMarkupAttached() is called exactly once
+ * for its lifecycle.
+ *
+ * https://issues.apache.org/jira/browse/WICKET-4361
+ *
+ * @since 1.5.5
+ */
+public class OnMarkupAttachedTest extends WicketTestCase
+{
+	@Test
+	public void onMarkupAttached()
+	{
+		AtomicInteger counter = new AtomicInteger(0);
+		OnMarkupAttachedPage page = new OnMarkupAttachedPage(counter);
+		tester.startPage(page);
+
+		assertEquals(3, counter.get());
+	}
+	
+	private static class OnMarkupAttachedPage extends WebPage implements IMarkupResourceStreamProvider
+	{
+		private final AtomicInteger counter;
+
+		private OnMarkupAttachedPage(AtomicInteger counter)
+		{
+			this.counter = counter;
+
+			WebMarkupContainer comp1 = new WebMarkupContainer("one")
+			{
+				@Override
+				protected void onMarkupAttached()
+				{
+					super.onMarkupAttached();
+					assertEquals(1, getCounter().getAndIncrement());
+				}
+			};
+			
+			WebMarkupContainer comp2 = new WebMarkupContainer("two")
+			{
+				@Override
+				protected void onMarkupAttached()
+				{
+					super.onMarkupAttached();
+					assertEquals(2, getCounter().getAndIncrement());
+				}
+			};
+			comp1.add(comp2);
+			add(comp1);
+		}
+
+		@Override
+		protected void onMarkupAttached()
+		{
+			super.onMarkupAttached();
+			assertEquals(0, counter.getAndIncrement());
+		}
+
+		private AtomicInteger getCounter()
+		{
+			return counter;
+		}
+
+		@Override
+		public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass)
+		{
+			return new StringResourceStream("<html><body><div wicket:id='one'><div wicket:id='two'></div></div></body></html>");
+		}
+	}
+}