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 2013/11/25 13:32:32 UTC

git commit: WICKET-5417 this.replaceWith is broken when called from onInitialize

Updated Branches:
  refs/heads/master 166dc9028 -> 296d552d7


WICKET-5417 this.replaceWith is broken when called from onInitialize

Allow calling #replaceWith() inside #onInitialize and #onBeforeRender


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

Branch: refs/heads/master
Commit: 296d552d7b0be2efd3ac7a691a8fd401e51496b6
Parents: 166dc90
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Nov 25 13:29:58 2013 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Nov 25 13:29:58 2013 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/wicket/Component.java  | 13 +++
 .../replacewith/BaseReplaceWithPanel.java       | 40 +++++++++
 .../wicket/component/replacewith/HomePage.html  | 67 +++++++++++++++
 .../wicket/component/replacewith/HomePage.java  | 30 +++++++
 .../wicket/component/replacewith/PanelB.html    | 10 +++
 .../wicket/component/replacewith/PanelB.java    | 33 ++++++++
 .../replacewith/ReplaceInConstructorPanel.java  | 30 +++++++
 .../ReplaceInOnBeforeRenderPanel.java           | 35 ++++++++
 .../replacewith/ReplaceInOnConfigurePanel.java  | 35 ++++++++
 .../replacewith/ReplaceInOnInitializePanel.java | 35 ++++++++
 .../component/replacewith/ReplaceWithTest.java  | 85 ++++++++++++++++++++
 11 files changed, 413 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/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 413e80c..bb5adfe 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Component.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Component.java
@@ -1159,8 +1159,21 @@ public abstract class Component
 		clearEnabledInHierarchyCache();
 		clearVisibleInHierarchyCache();
 
+		boolean beforeRenderSuperCallVerified = getRequestFlag(RFLAG_BEFORE_RENDER_SUPER_CALL_VERIFIED);
+		boolean initializeSuperCallVerified = getRequestFlag(RFLAG_INITIALIZE_SUPER_CALL_VERIFIED);
+
 		requestFlags = 0;
 
+		// preserve the super_call_verified flags if they were set. WICKET-5417
+		if (beforeRenderSuperCallVerified)
+		{
+			setRequestFlag(RFLAG_BEFORE_RENDER_SUPER_CALL_VERIFIED, true);
+		}
+		if (initializeSuperCallVerified)
+		{
+			setRequestFlag(RFLAG_INITIALIZE_SUPER_CALL_VERIFIED, true);
+		}
+
 		detachFeedback();
 
 		internalDetach();

http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/wicket-core/src/test/java/org/apache/wicket/component/replacewith/BaseReplaceWithPanel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/BaseReplaceWithPanel.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/BaseReplaceWithPanel.java
new file mode 100644
index 0000000..52b3c27
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/BaseReplaceWithPanel.java
@@ -0,0 +1,40 @@
+/*
+ * 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.component.replacewith;
+
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.markup.IMarkupResourceStreamProvider;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.StringResourceStream;
+
+/**
+ * A base panel for all replaceWith panels
+ */
+public class BaseReplaceWithPanel extends Panel implements IMarkupResourceStreamProvider
+{
+	public BaseReplaceWithPanel(String id)
+	{
+		super(id);
+	}
+
+	@Override
+	public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass)
+	{
+		return new StringResourceStream(getClass().getSimpleName());
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/wicket-core/src/test/java/org/apache/wicket/component/replacewith/HomePage.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/HomePage.html b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/HomePage.html
new file mode 100644
index 0000000..0d1d297
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/HomePage.html
@@ -0,0 +1,67 @@
+<!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">
+			<h2>Congratulations!</h2>
+			<p>
+				Your quick start works! This project is especially useful to
+                start developing your Wicket application or to create a test
+                case for a bug report.
+			</p>
+			<h3>Get started</h3>
+			<p>
+				You can even <a href="https://localhost:8443">switch to HTTPS</a>!
+			</p>
+			<p>
+				From here you can start hacking away at your application and
+                wow your clients:
+			</p>
+			<ul>
+				<li>work through <a href="http://wicket.apache.org/learn/examples" target="_blank" title="Hello world and friends">some examples</a></li>
+				<li>read <a href="http://wicket.apache.org/learn/books" target="_blank" title="Books about Wicket in English, German and Japanese">some books</a></li>
+				<li>find <a href="http://wicket.apache.org/learn/projects" target="_blank" title="Additional projects, components and libraries">additional components, projects and libraries</a></li>
+			</ul>
+			<h3>Get help</h3>
+			<p>
+				We are here to help!
+			</p>
+			<ul>
+				<li>join us on IRC on <a href="irc:%23%23wicket@irc.freenode.net">&#35;&#35;wicket@irc.freenode.net</a></li>
+				<li><a href="http://wicket-users.markmail.org/" target="_blank" title="Search the mailing list archives">search</a> our mailing list archives</li>
+				<li>ask a question on the <a href="http://wicket.apache.org/help/email.html">users list</a></li>
+			</ul>
+			<h3>Reporting a bug</h3>
+			<p>
+				Help us help you:
+			</p>
+			<ol>
+				<li>reproduce the bug with the <strong>least</strong> amount of code</li>
+				<li>create a unit test that shows the bug</li>
+				<li>fix the bug and create a patch</li>
+				<li>attach the result of step 1, 2 or 3 to a <a href="https://issues.apache.org/jira/browse/WICKET" target="_blank">JIRA issue</a></li>
+				<li>profit!</li>
+			</ol>
+			<p>
+				Please mention the correct Wicket version: <wicket:container wicket:id="version">1.5-SNAPSHOT</wicket:container>.
+			</p>
+            <p>
+                Custom Panel, should be Panel B:
+                <span wicket:id="panel"></span>
+            </p>
+		</div>
+		<div id="ft">
+		</div>
+	</body>
+</html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/wicket-core/src/test/java/org/apache/wicket/component/replacewith/HomePage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/HomePage.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/HomePage.java
new file mode 100644
index 0000000..f02cc36
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/HomePage.java
@@ -0,0 +1,30 @@
+/*
+ * 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.component.replacewith;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+public class HomePage extends WebPage {
+	private static final long serialVersionUID = 1L;
+
+	public HomePage()
+	{
+		add(new Label("version", getApplication().getFrameworkSettings().getVersion()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/wicket-core/src/test/java/org/apache/wicket/component/replacewith/PanelB.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/PanelB.html b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/PanelB.html
new file mode 100644
index 0000000..b50f21f
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/PanelB.html
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+<body>
+<wicket:panel>
+    <div style="padding: 100px">
+============= Panel B =============
+    </div>
+</wicket:panel>
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/wicket-core/src/test/java/org/apache/wicket/component/replacewith/PanelB.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/PanelB.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/PanelB.java
new file mode 100644
index 0000000..f38889b
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/PanelB.java
@@ -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.component.replacewith;
+
+import org.apache.wicket.markup.html.panel.Panel;
+
+public class PanelB extends Panel
+{
+    public PanelB(String id)
+    {
+        super(id);
+    }
+
+    @Override
+    protected void onInitialize()
+    {
+        super.onInitialize();
+    }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInConstructorPanel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInConstructorPanel.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInConstructorPanel.java
new file mode 100644
index 0000000..d96fa89
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInConstructorPanel.java
@@ -0,0 +1,30 @@
+/*
+ * 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.component.replacewith;
+
+/**
+ * A panel that uses #replaceWith in #onBeforeRender
+ */
+public class ReplaceInConstructorPanel extends BaseReplaceWithPanel
+{
+    public ReplaceInConstructorPanel(String id)
+    {
+        super(id);
+
+	    replaceWith(new PanelB(getId()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnBeforeRenderPanel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnBeforeRenderPanel.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnBeforeRenderPanel.java
new file mode 100644
index 0000000..26998e6
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnBeforeRenderPanel.java
@@ -0,0 +1,35 @@
+/*
+ * 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.component.replacewith;
+
+/**
+ * A panel that uses #replaceWith in #onBeforeRender
+ */
+public class ReplaceInOnBeforeRenderPanel extends BaseReplaceWithPanel
+{
+    public ReplaceInOnBeforeRenderPanel(String id)
+    {
+        super(id);
+    }
+
+	@Override
+	protected void onBeforeRender()
+	{
+		super.onBeforeRender();
+		replaceWith(new PanelB(getId()));
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnConfigurePanel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnConfigurePanel.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnConfigurePanel.java
new file mode 100644
index 0000000..d5fa364
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnConfigurePanel.java
@@ -0,0 +1,35 @@
+/*
+ * 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.component.replacewith;
+
+/**
+ * A panel that uses #replaceWith in #onBeforeRender
+ */
+public class ReplaceInOnConfigurePanel extends BaseReplaceWithPanel
+{
+    public ReplaceInOnConfigurePanel(String id)
+    {
+        super(id);
+    }
+
+	@Override
+	protected void onConfigure()
+	{
+		super.onConfigure();
+		replaceWith(new PanelB(getId()));
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnInitializePanel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnInitializePanel.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnInitializePanel.java
new file mode 100644
index 0000000..a89edbd
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnInitializePanel.java
@@ -0,0 +1,35 @@
+/*
+ * 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.component.replacewith;
+
+/**
+ * A panel that uses #replaceWith in #onInitialize
+ */
+public class ReplaceInOnInitializePanel extends BaseReplaceWithPanel
+{
+    public ReplaceInOnInitializePanel(String id)
+    {
+        super(id);
+    }
+
+    @Override
+    protected void onInitialize()
+    {
+        super.onInitialize();
+        replaceWith(new PanelB(getId()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/296d552d/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceWithTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceWithTest.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceWithTest.java
new file mode 100644
index 0000000..5908bd1
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceWithTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.component.replacewith;
+
+import org.apache.wicket.WicketTestCase;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Tests for Component#replaceWith() method
+ */
+public class ReplaceWithTest extends WicketTestCase
+{
+	@Rule
+	public ExpectedException expectedException = ExpectedException.none();
+
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-5417
+	 */
+	@Test
+	public void replaceWithInOnInitialize()
+	{
+		HomePage page = new HomePage();
+		page.add(new ReplaceInOnInitializePanel("panel"));
+
+		tester.startPage(page);
+		tester.assertRenderedPage(HomePage.class);
+	}
+
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-5417
+	 */
+	@Test
+	public void replaceWithInOnBeforeRender()
+	{
+		HomePage page = new HomePage();
+		page.add(new ReplaceInOnBeforeRenderPanel("panel"));
+
+		tester.startPage(page);
+		tester.assertRenderedPage(HomePage.class);
+	}
+
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-5417
+	 */
+	@Test
+	public void replaceWithInOnConfigure()
+	{
+		HomePage page = new HomePage();
+		page.add(new ReplaceInOnConfigurePanel("panel"));
+
+		tester.startPage(page);
+		tester.assertRenderedPage(HomePage.class);
+	}
+
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-5417
+	 */
+	@Test
+	public void replaceWithInConstructor()
+	{
+		HomePage page = new HomePage();
+
+		expectedException.expect(IllegalStateException.class);
+		expectedException.
+		    expectMessage("This method can only be called on a component that has already been added to its parent.");
+
+		page.add(new ReplaceInConstructorPanel("panel"));
+	}
+}