(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Tue, 27 Jul 2010 19:08:49 +0000 (19:08 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Tue, 27 Jul 2010 19:08:49 +0000 (19:08 +0000)
wicket/components/src/main/java/org/wamblee/wicket/page/AbstractPageBehavior.java
wicket/components/src/main/java/org/wamblee/wicket/page/CompositePageBehavior.java
wicket/components/src/main/java/org/wamblee/wicket/page/DisableCachingBehavior.java
wicket/components/src/main/java/org/wamblee/wicket/page/ExpirePageImmediatelyBehavior.java
wicket/components/src/main/java/org/wamblee/wicket/page/LoggingPageBehavior.java [new file with mode: 0644]
wicket/components/src/main/java/org/wamblee/wicket/page/PageBehavior.java
wicket/components/src/main/java/org/wamblee/wicket/page/WebApplicationBasePage.java

index 81652596ac82570966b1ef2af55ca9462d5a5314..bf9262e46889b18cc61da10b0092eff3c3312c02 100644 (file)
@@ -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   
+    }
 
 }
index d6946de6b5ee58310367c8ce6718b79aa36b289e..05208b3faf80630f89583088f0ccd9d4fc816de4 100644 (file)
@@ -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);
+        }
+    }
 
 }
index 04003a2c4769b4d0a4a740e904f39d1349db62be..b9bf3e62a779a968ddbc802a59af3a7a61a963b4 100644 (file)
@@ -20,8 +20,7 @@ import org.apache.wicket.protocol.http.WebResponse;
 
 /**
  * <p>
- * 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. 
  * </p>
  * 
  * <p>
@@ -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) {
index a1416d2aaedad592079573f74345062467332ed6..efc170a24df202b0bdb5358ff30599a7f641dd97 100644 (file)
@@ -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 (file)
index 0000000..6d9a369
--- /dev/null
@@ -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);
+    }
+    
+
+}
index dbaf7dc0c749a37de5c2d5cb2381cc9cb60ea600..ac17a063b1cd6d8a469dcbd2e3d5578465d8555a 100644 (file)
@@ -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);
 }
index de46e9e32ab6ec801405d68e2e50dafef1b4315e..97e41a04c066cc6bdf59d6cbd134781e3aa95690 100644 (file)
@@ -129,4 +129,10 @@ public class WebApplicationBasePage extends WebPage {
         super.onAfterRender();
         behaviors.onAfterRender(this);
     }
+    
+    @Override
+    protected void onDetach() {
+        super.onDetach();
+        behaviors.onDetach(this);
+    }
 }