/* * 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 javax.persistence.EntityManager; import org.apache.wicket.IPageMap; import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.model.IModel; import org.apache.wicket.protocol.http.WebResponse; /** * Base page for wicket applications that allows customization of various * bahaviors of the page. This page has no associated markup. * * The utility methods {@link #disableCaching()}, {@link #expireImmediately()}, * and {@link #flushEntityManagerAfterRender(EntityManager)} are provide for * quicly adding behaviors. Alternatively, the method * {@link #addBehavior(PageBehavior)} can be used. * * @author Erik Brakkee * */ public class WebApplicationBasePage extends WebPage { private CompositePageBehavior behaviors; protected WebApplicationBasePage() { super(); setEnabled(false); init(); } protected WebApplicationBasePage(final IModel aModel) { super(aModel); init(); } protected WebApplicationBasePage(final IPageMap aPageMap) { super(aPageMap); init(); } protected WebApplicationBasePage(final IPageMap aPageMap, final IModel aModel) { super(aPageMap, aModel); init(); } protected WebApplicationBasePage(final PageParameters aParameters) { super(aParameters); init(); } protected WebApplicationBasePage(final IPageMap aPageMap, final PageParameters aParameters) { super(aPageMap, aParameters); init(); } private void init() { behaviors = new CompositePageBehavior(); } /** * Disables caching. This implies expiry of the page from the page map. */ protected void disableCaching() { addBehavior(new DisableCachingBehavior()); } /** * Expires the page immediately. Refresh in the browser will lead to an * expired page. */ protected void expireImmediately() { addBehavior(new ExpirePageImmediatelyBehavior()); } /** * Adds a specific behavior to the page. * * @param aBehavior * Behavior to add. */ public void addBehavior(PageBehavior aBehavior) { behaviors.add(aBehavior); } @Override protected void onBeforeRender() { behaviors.onBeforeRender(this); super.onBeforeRender(); } @Override protected void setHeaders(WebResponse aResponse) { super.setHeaders(aResponse); behaviors.setHeaders(this, aResponse); } @Override protected void onAfterRender() { super.onAfterRender(); behaviors.onAfterRender(this); } @Override protected void onDetach() { super.onDetach(); behaviors.onDetach(this); } }