2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.wicket.behavior;
18 import javax.persistence.EntityManager;
20 import org.apache.wicket.IPageMap;
21 import org.apache.wicket.PageParameters;
22 import org.apache.wicket.markup.html.WebPage;
23 import org.apache.wicket.model.IModel;
24 import org.apache.wicket.protocol.http.WebResponse;
27 * Base page for wicket applications that allows customization of various bahaviors of the
28 * page. This page has no associated markup.
30 * The utility methods {@link #disableCaching()}, {@link #expireImmediately()},
31 * and {@link #flushEntityManagerAfterRender(EntityManager)} are provide for quicly adding
32 * behaviors. Alternatively, the method {@link #addBehavior(PageBehavior)} can be used.
34 * @author Erik Brakkee
37 public class WebApplicationBasePage extends WebPage {
39 private CompositePageBehavior behaviors;
41 protected WebApplicationBasePage() {
46 protected WebApplicationBasePage(final IModel<?> model)
52 protected WebApplicationBasePage(final IPageMap pageMap)
58 protected WebApplicationBasePage(final IPageMap pageMap, final IModel<?> model)
60 super(pageMap, model);
64 protected WebApplicationBasePage(final PageParameters parameters)
70 protected WebApplicationBasePage(final IPageMap pageMap, final PageParameters parameters)
72 super(pageMap, parameters);
77 behaviors = new CompositePageBehavior();
81 * Disables caching. This implies expiry of the page from the page map.
83 protected void disableCaching() {
84 addBehavior(new DisableCachingBehavior());
88 * Expires the page immediately. Refresh in the browser will lead to an expired page.
90 protected void expireImmediately() {
91 addBehavior(new ExpirePageImmediatelyBehavior());
95 * Flushes the entitymanager immedately after rendering to make sure that errors are
97 * @param aEntityManager Contextual reference to an entity manager.
99 protected void flushEntityManagerAfterRender(EntityManager aEntityManager) {
100 addBehavior(new FlushEntityManagerBehavior(aEntityManager));
104 * Adds a specific behavior to the page.
105 * @param aBehavior Behavior to add.
107 public void addBehavior(PageBehavior aBehavior) {
108 behaviors.add(aBehavior);
112 protected void onBeforeRender() {
113 behaviors.onBeforeRender(this);
114 super.onBeforeRender();
118 protected void setHeaders(WebResponse aResponse) {
119 super.setHeaders(aResponse);
120 behaviors.setHeaders(this, aResponse);
124 protected void onAfterRender() {
125 super.onAfterRender();
126 behaviors.onAfterRender(this);