*/
package org.wamblee.wicket.behavior;
+import javax.persistence.EntityManager;
+import javax.transaction.UserTransaction;
+
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();
+ init();
}
protected WebApplicationBasePage(final IModel<?> model)
{
super(model);
+ init();
}
protected WebApplicationBasePage(final IPageMap pageMap)
{
super(pageMap);
+ init();
}
protected WebApplicationBasePage(final IPageMap pageMap, final IModel<?> model)
{
super(pageMap, model);
+ init();
}
protected WebApplicationBasePage(final PageParameters parameters)
{
super(parameters);
+ init();
}
protected WebApplicationBasePage(final IPageMap pageMap, final PageParameters parameters)
{
super(pageMap, parameters);
+ 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());
+ }
+
+ /**
+ * Flushes the entitymanager immedately after rendering to make sure that errors are
+ * caught early.
+ * @param aEntityManager Contextual reference to an entity manager.
+ */
+ protected void flushEntityManagerAfterRender(EntityManager aEntityManager) {
+ addBehavior(new FlushEntityManagerBehavior(aEntityManager));
+ }
+
+ /**
+ * 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);
}
}