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/15 10:12:00 UTC

git commit: WICKET-5415 Do not initialize pages which were not rendered WICKET-5387 Page#onInitialize called after an exception in the constructor of Page

Updated Branches:
  refs/heads/wicket-6.x 4b43ba654 -> 86a34bfc0


WICKET-5415 Do not initialize pages which were not rendered
WICKET-5387 Page#onInitialize called after an exception in the constructor of Page


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

Branch: refs/heads/wicket-6.x
Commit: 86a34bfc03c3ae6bb56e1e23453fdead603ec7ab
Parents: 4b43ba6
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Fri Nov 15 11:11:11 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Fri Nov 15 11:11:51 2013 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/wicket/Page.java   | 15 +++-
 .../wicket/dontstoreunrendered/BasePage.html    | 15 ++++
 .../wicket/dontstoreunrendered/BasePage.java    | 40 ++++++++++
 .../DontStoreNotRenderedPageTest.java           | 84 ++++++++++++++++++++
 .../wicket/dontstoreunrendered/PageA.html       | 15 ++++
 .../wicket/dontstoreunrendered/PageA.java       | 28 +++++++
 .../wicket/dontstoreunrendered/PageB.java       | 50 ++++++++++++
 .../wicket/dontstoreunrendered/PageC.java       | 24 ++++++
 8 files changed, 270 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/86a34bfc/wicket-core/src/main/java/org/apache/wicket/Page.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/Page.java b/wicket-core/src/main/java/org/apache/wicket/Page.java
index 1c811aa..87d32bc 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Page.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Page.java
@@ -284,10 +284,23 @@ public abstract class Page extends MarkupContainer implements IRedirectListener,
 		{
 			setFlag(FLAG_IS_DIRTY, true);
 			setNextAvailableId();
-			pageManager.touchPage(this);
+
+			if (isInitialization == false)
+			{
+				pageManager.touchPage(this);
+			}
 		}
 	}
 
+	@Override
+	protected void onInitialize()
+	{
+		super.onInitialize();
+
+		final IPageManager pageManager = getSession().getPageManager();
+		pageManager.touchPage(this);
+	}
+
 	/**
 	 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL.
 	 * 

http://git-wip-us.apache.org/repos/asf/wicket/blob/86a34bfc/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/BasePage.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/BasePage.html b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/BasePage.html
new file mode 100644
index 0000000..1ce3521
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/BasePage.html
@@ -0,0 +1,15 @@
+<!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="bd">
+			Class name: <span wicket:id="className"></span>
+			<wicket:child/>
+		</div>
+	</body>
+</html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/86a34bfc/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/BasePage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/BasePage.java b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/BasePage.java
new file mode 100644
index 0000000..23d16b5
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/BasePage.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.dontstoreunrendered;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+
+/**
+ * A base page that provides the markup for PageA, PageB and PageC
+ */
+class BasePage extends WebPage {
+	private static final long serialVersionUID = 1L;
+
+	public BasePage() {
+
+		add(new Label("className", new AbstractReadOnlyModel<String>() {
+
+			@Override
+			public String getObject()
+			{
+				return getPageClass().getSimpleName();
+			}
+		}));
+    }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/86a34bfc/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/DontStoreNotRenderedPageTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/DontStoreNotRenderedPageTest.java b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/DontStoreNotRenderedPageTest.java
new file mode 100644
index 0000000..e1adb12
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/DontStoreNotRenderedPageTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.dontstoreunrendered;
+
+import org.apache.wicket.IPageManagerProvider;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.mock.MockPageManager;
+import org.apache.wicket.page.IManageablePage;
+import org.apache.wicket.page.IPageManager;
+import org.apache.wicket.page.IPageManagerContext;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.util.tester.WicketTester;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * https://issues.apache.org/jira/browse/WICKET-5415
+ */
+public class DontStoreNotRenderedPageTest extends WicketTestCase
+{
+	@Override
+	protected WicketTester newWicketTester(WebApplication app)
+	{
+		return new WicketTester(app)
+		{
+			@Override
+			protected IPageManagerProvider newTestPageManagerProvider()
+			{
+				return new IPageManagerProvider()
+				{
+					@Override
+					public IPageManager get(IPageManagerContext context)
+					{
+						return new MockPageManager()
+						{
+							@Override
+							public void touchPage(IManageablePage page)
+							{
+								Assert.assertFalse("PageB should not be touched!", page instanceof PageB);
+								super.touchPage(page);
+							}
+						};
+					}
+				};
+			}
+		};
+	}
+
+	/**
+	 * Start with PageA.
+	 * Then click a link to go to PageB.
+	 * PageB throws a RestartResponseException(PageC) in its constructor, so
+	 * it shouldn't be neither initialized nor rendered.
+	 * PageC is rendered.
+	 *
+	 * Verifies that PageB is not initialized, rendered and stored by PageManager
+	 */
+	@Test
+	public void dontStoreNotRenderedPage()
+	{
+		tester.startPage(PageA.class);
+		tester.clickLink("goToB");
+
+		tester.assertRenderedPage(PageC.class);
+
+		assertFalse(PageB.PAGE_B_RENDERED.get());
+		assertFalse(PageB.PAGE_B_INITIALIZED.get());
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/86a34bfc/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageA.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageA.html b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageA.html
new file mode 100644
index 0000000..c18127f
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageA.html
@@ -0,0 +1,15 @@
+<!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>
+		<wicket:extend>
+			<br/>
+			<a wicket:id="goToB">Go to PageB</a>
+		</wicket:extend>
+	</body>
+</html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/86a34bfc/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageA.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageA.java b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageA.java
new file mode 100644
index 0000000..86184b7
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageA.java
@@ -0,0 +1,28 @@
+/*
+ * 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.dontstoreunrendered;
+
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+
+public class PageA extends BasePage {
+
+	public PageA() {
+		super();
+
+		add(new BookmarkablePageLink<Void>("goToB", PageB.class));
+    }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/86a34bfc/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageB.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageB.java b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageB.java
new file mode 100644
index 0000000..f4eb63c
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageB.java
@@ -0,0 +1,50 @@
+/*
+ * 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.dontstoreunrendered;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.wicket.RestartResponseException;
+
+/**
+ *
+ */
+public class PageB extends BasePage {
+
+	static final AtomicBoolean PAGE_B_INITIALIZED = new AtomicBoolean(false);
+	static final AtomicBoolean PAGE_B_RENDERED    = new AtomicBoolean(false);
+
+	public PageB() {
+		super();
+
+		throw new RestartResponseException(PageC.class);
+	}
+
+	@Override
+	protected void onInitialize()
+	{
+		super.onInitialize();
+		PAGE_B_INITIALIZED.set(true);
+	}
+
+	@Override
+	public void renderPage()
+	{
+		super.renderPage();
+		PAGE_B_RENDERED.set(true);
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/86a34bfc/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageC.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageC.java b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageC.java
new file mode 100644
index 0000000..ec60816
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/PageC.java
@@ -0,0 +1,24 @@
+/*
+ * 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.dontstoreunrendered;
+
+public class PageC extends BasePage {
+
+	public PageC() {
+		super();
+    }
+}