From ece691138807a2d36eed9cf126367279dbbf7577 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Thu, 29 Jul 2010 21:54:18 +0000 Subject: [PATCH] --- .../wicket/page/FlushEntityManagerBehavior.java | 15 ++++++++++----- .../org/wamblee/wicket/page/PageBehavior.java | 2 +- .../wicket/page/WebApplicationBasePage.java | 15 ++------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/wicket/components/src/main/java/org/wamblee/wicket/page/FlushEntityManagerBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/page/FlushEntityManagerBehavior.java index 4362faa7..a8cf15d7 100644 --- a/wicket/components/src/main/java/org/wamblee/wicket/page/FlushEntityManagerBehavior.java +++ b/wicket/components/src/main/java/org/wamblee/wicket/page/FlushEntityManagerBehavior.java @@ -30,25 +30,24 @@ import org.apache.wicket.markup.html.WebPage; * @author Erik Brakkee * */ -public class FlushEntityManagerBehavior extends AbstractPageBehavior { +public abstract class FlushEntityManagerBehavior extends AbstractPageBehavior { private static final Logger LOGGER = Logger .getLogger(FlushEntityManagerBehavior.class.getName()); - private EntityManager entityManager; - /** * Constructs the behavior. * * @param aEntityManager * Contextual reference to an entitymanager. */ - public FlushEntityManagerBehavior(EntityManager aEntityManager) { - entityManager = aEntityManager; + public FlushEntityManagerBehavior() { + // Empty. } @Override public void onAfterRender(WebPage aPage) { + EntityManager entityManager = getEntityManager(); try { if (entityManager.isOpen()) { entityManager.flush(); @@ -61,5 +60,11 @@ public class FlushEntityManagerBehavior extends AbstractPageBehavior { LOGGER.log(Level.WARNING, "Could not flush entitymanager", e); } } + + /** + * Gets the entity mmanager to flush. + * @return Entity manager. + */ + public abstract EntityManager getEntityManager(); } diff --git a/wicket/components/src/main/java/org/wamblee/wicket/page/PageBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/page/PageBehavior.java index ac17a063..a8d4f931 100644 --- a/wicket/components/src/main/java/org/wamblee/wicket/page/PageBehavior.java +++ b/wicket/components/src/main/java/org/wamblee/wicket/page/PageBehavior.java @@ -22,7 +22,7 @@ import org.apache.wicket.protocol.http.WebResponse; /** * Page behavior interface. This provides a mechanism to extend page behavior - * without subclassing. + * without subclassing. Implementations of this interface should be serializable. * * @author Erik Brakkee */ diff --git a/wicket/components/src/main/java/org/wamblee/wicket/page/WebApplicationBasePage.java b/wicket/components/src/main/java/org/wamblee/wicket/page/WebApplicationBasePage.java index 7a90c764..b0ac386d 100644 --- a/wicket/components/src/main/java/org/wamblee/wicket/page/WebApplicationBasePage.java +++ b/wicket/components/src/main/java/org/wamblee/wicket/page/WebApplicationBasePage.java @@ -41,7 +41,7 @@ public class WebApplicationBasePage extends WebPage { protected WebApplicationBasePage() { super(); - + setEnabled(false); init(); } @@ -92,17 +92,6 @@ public class WebApplicationBasePage extends WebPage { 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. * @@ -130,7 +119,7 @@ public class WebApplicationBasePage extends WebPage { super.onAfterRender(); behaviors.onAfterRender(this); } - + @Override protected void onDetach() { super.onDetach(); -- 2.31.1