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;
19 import javax.transaction.UserTransaction;
21 import org.apache.wicket.IPageMap;
22 import org.apache.wicket.PageParameters;
23 import org.apache.wicket.markup.html.WebPage;
24 import org.apache.wicket.model.IModel;
25 import org.apache.wicket.protocol.http.WebResponse;
28 * Base page for wicket applications that allows customization of various bahaviors of the
29 * page. This page has no associated markup.
31 * The utility methods {@link #disableCaching()}, {@link #expireImmediately()},
32 * and {@link #flushEntityManagerAfterRender(EntityManager)} are provide for quicly adding
33 * behaviors. Alternatively, the method {@link #addBehavior(PageBehavior)} can be used.
35 * @author Erik Brakkee
38 public class WebApplicationBasePage extends WebPage {
40 private CompositePageBehavior behaviors;
42 protected WebApplicationBasePage() {
47 protected WebApplicationBasePage(final IModel<?> model)
53 protected WebApplicationBasePage(final IPageMap pageMap)
59 protected WebApplicationBasePage(final IPageMap pageMap, final IModel<?> model)
61 super(pageMap, model);
65 protected WebApplicationBasePage(final PageParameters parameters)
71 protected WebApplicationBasePage(final IPageMap pageMap, final PageParameters parameters)
73 super(pageMap, parameters);
78 behaviors = new CompositePageBehavior();
82 * Disables caching. This implies expiry of the page from the page map.
84 protected void disableCaching() {
85 addBehavior(new DisableCachingBehavior());
89 * Expires the page immediately. Refresh in the browser will lead to an expired page.
91 protected void expireImmediately() {
92 addBehavior(new ExpirePageImmediatelyBehavior());
96 * Flushes the entitymanager immedately after rendering to make sure that errors are
98 * @param aEntityManager Contextual reference to an entity manager.
100 protected void flushEntityManagerAfterRender(EntityManager aEntityManager) {
101 addBehavior(new FlushEntityManagerBehavior(aEntityManager));
105 * Adds a specific behavior to the page.
106 * @param aBehavior Behavior to add.
108 public void addBehavior(PageBehavior aBehavior) {
109 behaviors.add(aBehavior);
113 protected void onBeforeRender() {
114 behaviors.onBeforeRender(this);
115 super.onBeforeRender();
119 protected void setHeaders(WebResponse aResponse) {
120 super.setHeaders(aResponse);
121 behaviors.setHeaders(this, aResponse);
125 protected void onAfterRender() {
126 super.onAfterRender();
127 behaviors.onAfterRender(this);