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.page;
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
29 * bahaviors of the page. This page has no associated markup.
31 * The utility methods {@link #disableCaching()}, {@link #expireImmediately()},
32 * and {@link #flushEntityManagerAfterRender(EntityManager)} are provide for
33 * quicly adding behaviors. Alternatively, the method
34 * {@link #addBehavior(PageBehavior)} can be used.
36 * @author Erik Brakkee
39 public class WebApplicationBasePage extends WebPage {
41 private CompositePageBehavior behaviors;
43 protected WebApplicationBasePage() {
48 protected WebApplicationBasePage(final IModel<?> model) {
53 protected WebApplicationBasePage(final IPageMap pageMap) {
58 protected WebApplicationBasePage(final IPageMap pageMap,
59 final IModel<?> model) {
60 super(pageMap, model);
64 protected WebApplicationBasePage(final PageParameters parameters) {
69 protected WebApplicationBasePage(final IPageMap pageMap,
70 final PageParameters parameters) {
71 super(pageMap, parameters);
76 behaviors = new CompositePageBehavior();
80 * Disables caching. This implies expiry of the page from the page map.
82 protected void disableCaching() {
83 addBehavior(new DisableCachingBehavior());
87 * Expires the page immediately. Refresh in the browser will lead to an
90 protected void expireImmediately() {
91 addBehavior(new ExpirePageImmediatelyBehavior());
95 * Flushes the entitymanager immedately after rendering to make sure that
96 * errors are caught early.
98 * @param aEntityManager
99 * Contextual reference to an entity manager.
101 protected void flushEntityManagerAfterRender(EntityManager aEntityManager) {
102 addBehavior(new FlushEntityManagerBehavior(aEntityManager));
106 * Adds a specific behavior to the page.
111 public void addBehavior(PageBehavior aBehavior) {
112 behaviors.add(aBehavior);
116 protected void onBeforeRender() {
117 behaviors.onBeforeRender(this);
118 super.onBeforeRender();
122 protected void setHeaders(WebResponse aResponse) {
123 super.setHeaders(aResponse);
124 behaviors.setHeaders(this, aResponse);
128 protected void onAfterRender() {
129 super.onAfterRender();
130 behaviors.onAfterRender(this);
134 protected void onDetach() {
136 behaviors.onDetach(this);