From 7c84bf5c736350646ace673f546b1f7737757322 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 27 Jul 2010 19:08:49 +0000 Subject: [PATCH] --- .../wicket/page/AbstractPageBehavior.java | 13 ++-- .../wicket/page/CompositePageBehavior.java | 21 ++++--- .../wicket/page/DisableCachingBehavior.java | 5 +- .../page/ExpirePageImmediatelyBehavior.java | 4 +- .../wicket/page/LoggingPageBehavior.java | 63 +++++++++++++++++++ .../org/wamblee/wicket/page/PageBehavior.java | 5 ++ .../wicket/page/WebApplicationBasePage.java | 6 ++ 7 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 wicket/components/src/main/java/org/wamblee/wicket/page/LoggingPageBehavior.java diff --git a/wicket/components/src/main/java/org/wamblee/wicket/page/AbstractPageBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/page/AbstractPageBehavior.java index 81652596..bf9262e4 100644 --- a/wicket/components/src/main/java/org/wamblee/wicket/page/AbstractPageBehavior.java +++ b/wicket/components/src/main/java/org/wamblee/wicket/page/AbstractPageBehavior.java @@ -34,18 +34,23 @@ public abstract class AbstractPageBehavior implements PageBehavior { } @Override - public void onAfterRender(WebPage aPage) { + public void onBeforeRender(WebPage aPage) { // Empty } @Override - public void onBeforeRender(WebPage aPage) { + public void setHeaders(WebPage aPage, WebResponse aResponse) { // Empty } - + @Override - public void setHeaders(WebPage aPage, WebResponse aResponse) { + public void onAfterRender(WebPage aPage) { // Empty } + + @Override + public void onDetach(WebPage aPage) { + // Empty + } } diff --git a/wicket/components/src/main/java/org/wamblee/wicket/page/CompositePageBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/page/CompositePageBehavior.java index d6946de6..05208b3f 100644 --- a/wicket/components/src/main/java/org/wamblee/wicket/page/CompositePageBehavior.java +++ b/wicket/components/src/main/java/org/wamblee/wicket/page/CompositePageBehavior.java @@ -53,13 +53,6 @@ public class CompositePageBehavior implements PageBehavior { behaviors.add(aBehavior); } - @Override - public void onAfterRender(WebPage aPage) { - for (PageBehavior behavior : behaviors) { - behavior.onAfterRender(aPage); - } - } - @Override public void onBeforeRender(WebPage aPage) { for (PageBehavior behavior : behaviors) { @@ -73,5 +66,19 @@ public class CompositePageBehavior implements PageBehavior { behavior.setHeaders(aPage, aResponse); } } + + @Override + public void onAfterRender(WebPage aPage) { + for (PageBehavior behavior : behaviors) { + behavior.onAfterRender(aPage); + } + } + + @Override + public void onDetach(WebPage aPage) { + for (PageBehavior behavior : behaviors) { + behavior.onDetach(aPage); + } + } } diff --git a/wicket/components/src/main/java/org/wamblee/wicket/page/DisableCachingBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/page/DisableCachingBehavior.java index 04003a2c..b9bf3e62 100644 --- a/wicket/components/src/main/java/org/wamblee/wicket/page/DisableCachingBehavior.java +++ b/wicket/components/src/main/java/org/wamblee/wicket/page/DisableCachingBehavior.java @@ -20,8 +20,7 @@ import org.apache.wicket.protocol.http.WebResponse; /** *

- * Behavior to disable browser caching. This also means that the page - * automatically expires the first time after it is rendered. + * Behavior to disable browser caching. *

* *

@@ -34,7 +33,7 @@ import org.apache.wicket.protocol.http.WebResponse; * @author Erik Brakkee * */ -public class DisableCachingBehavior extends ExpirePageImmediatelyBehavior { +public class DisableCachingBehavior extends AbstractPageBehavior { @Override public void setHeaders(WebPage aPage, WebResponse aResponse) { diff --git a/wicket/components/src/main/java/org/wamblee/wicket/page/ExpirePageImmediatelyBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/page/ExpirePageImmediatelyBehavior.java index a1416d2a..efc170a2 100644 --- a/wicket/components/src/main/java/org/wamblee/wicket/page/ExpirePageImmediatelyBehavior.java +++ b/wicket/components/src/main/java/org/wamblee/wicket/page/ExpirePageImmediatelyBehavior.java @@ -19,7 +19,7 @@ import org.apache.wicket.markup.html.WebPage; /** * Page which will be removed from the page map after rendering so it can be - * viewed only once. + * viewed only once. Even a refresh of the page will fail. * * @author Erik Brakkee * @@ -27,7 +27,7 @@ import org.apache.wicket.markup.html.WebPage; public class ExpirePageImmediatelyBehavior extends AbstractPageBehavior { @Override - public void onAfterRender(WebPage aPage) { + public void onDetach(WebPage aPage) { aPage.getPageMap().remove(aPage); } diff --git a/wicket/components/src/main/java/org/wamblee/wicket/page/LoggingPageBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/page/LoggingPageBehavior.java new file mode 100644 index 00000000..6d9a3691 --- /dev/null +++ b/wicket/components/src/main/java/org/wamblee/wicket/page/LoggingPageBehavior.java @@ -0,0 +1,63 @@ +/* + * Copyright 2005-2010 the original author or authors. + * + * Licensed 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.wamblee.wicket.page; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.protocol.http.WebResponse; + +/** + * Logs page events. + * + * @author Erik Brakkee + */ +public class LoggingPageBehavior implements PageBehavior { + + private static final Logger LOG = Logger.getLogger(LoggingPageBehavior.class.getName()); + + private Level level; + + /** + * Constructs the behavior. + */ + public LoggingPageBehavior(Level aLevel) { + level = aLevel; + } + + @Override + public void onBeforeRender(WebPage aPage) { + LOG.log(level, "onbeforeRender: " + aPage); + } + + @Override + public void setHeaders(WebPage aPage, WebResponse aResponse) { + LOG.log(level,"setHeaders: " + aPage + " " + aResponse); + } + + @Override + public void onAfterRender(WebPage aPage) { + LOG.log(level, "onAfterRender: " + aPage); + } + + @Override + public void onDetach(WebPage aPage) { + LOG.log(level, "onDetach: " + aPage); + } + + +} diff --git a/wicket/components/src/main/java/org/wamblee/wicket/page/PageBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/page/PageBehavior.java index dbaf7dc0..ac17a063 100644 --- a/wicket/components/src/main/java/org/wamblee/wicket/page/PageBehavior.java +++ b/wicket/components/src/main/java/org/wamblee/wicket/page/PageBehavior.java @@ -53,4 +53,9 @@ public interface PageBehavior extends Serializable { * Page this is called for. */ void onAfterRender(WebPage aPage); + + /** + * To be called in the {@link Page#onDetach + */ + void onDetach(WebPage aPage); } diff --git a/wicket/components/src/main/java/org/wamblee/wicket/page/WebApplicationBasePage.java b/wicket/components/src/main/java/org/wamblee/wicket/page/WebApplicationBasePage.java index de46e9e3..97e41a04 100644 --- a/wicket/components/src/main/java/org/wamblee/wicket/page/WebApplicationBasePage.java +++ b/wicket/components/src/main/java/org/wamblee/wicket/page/WebApplicationBasePage.java @@ -129,4 +129,10 @@ public class WebApplicationBasePage extends WebPage { super.onAfterRender(); behaviors.onAfterRender(this); } + + @Override + protected void onDetach() { + super.onDetach(); + behaviors.onDetach(this); + } } -- 2.31.1