[weld-commits] Weld SVN: r4203 - extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Mon Oct 19 18:48:56 EDT 2009


Author: cpopetz
Date: 2009-10-19 18:48:56 -0400 (Mon, 19 Oct 2009)
New Revision: 4203

Modified:
   extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldApplication.java
   extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldRequestCycle.java
   extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldWebRequestCycleProcessor.java
Log:
Update for new api, make jetty-compatible, make wicket.detach() compatible

Modified: extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldApplication.java
===================================================================
--- extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldApplication.java	2009-10-19 22:44:36 UTC (rev 4202)
+++ extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldApplication.java	2009-10-19 22:48:56 UTC (rev 4203)
@@ -29,15 +29,13 @@
 public abstract class WeldApplication extends WebApplication
 {
    
-   private final NonContextual<WeldComponentInstantiationListener> weldComponentInstantiationListener;
-   private final NonContextual<WeldWebRequestCycleProcessor> weldWebRequestCycleProcessor;
+   private NonContextual<WeldComponentInstantiationListener> weldComponentInstantiationListener;
+   private NonContextual<WeldWebRequestCycleProcessor> weldWebRequestCycleProcessor;
 
    /**
     */
    public WeldApplication()
    {
-      this.weldComponentInstantiationListener = new NonContextual<WeldComponentInstantiationListener>(BeanManagerLookup.getBeanManager(), WeldComponentInstantiationListener.class);
-      this.weldWebRequestCycleProcessor = new NonContextual<WeldWebRequestCycleProcessor>(BeanManagerLookup.getBeanManager(), WeldWebRequestCycleProcessor.class);
    }
 
    /**
@@ -49,6 +47,8 @@
    protected void internalInit() 
    {
       super.internalInit();
+      this.weldComponentInstantiationListener = new NonContextual<WeldComponentInstantiationListener>(BeanManagerLookup.getBeanManager(), WeldComponentInstantiationListener.class);
+      this.weldWebRequestCycleProcessor = new NonContextual<WeldWebRequestCycleProcessor>(BeanManagerLookup.getBeanManager(), WeldWebRequestCycleProcessor.class);
       addComponentInstantiationListener(weldComponentInstantiationListener.newInstance().produce().inject().get());
    }
 

Modified: extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldRequestCycle.java
===================================================================
--- extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldRequestCycle.java	2009-10-19 22:44:36 UTC (rev 4202)
+++ extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldRequestCycle.java	2009-10-19 22:48:56 UTC (rev 4203)
@@ -21,12 +21,12 @@
 import org.jboss.weld.Container;
 import org.jboss.weld.context.ContextLifecycle;
 import org.jboss.weld.context.ConversationContext;
+import org.jboss.weld.conversation.ConversationImpl;
 import org.jboss.weld.conversation.ConversationManager;
 import org.jboss.weld.servlet.ConversationBeanStore;
 
 /**
- * WeldRequestCycle is a subclass of the standard wicket WebRequestCycle
- * which:
+ * WeldRequestCycle is a subclass of the standard wicket WebRequestCycle which:
  * <ul>
  * <li>restores long-running conversations specified in wicket page metadata
  * when a page target is first used.
@@ -34,12 +34,13 @@
  * the above metadata
  * <li>propagates long running conversations across redirects through the use of
  * a request parameter if the redirect is handled with a BookmarkablePageRequest
- * <li>Sets up the conversational context
+ * <li>Sets up the conversational context when the request target is set
+ * <li>Tears down the conversation context on detach() of the RequestCycle
  * </ul>
  * 
- * @see WeldWebRequestCycleProcessor Which handles propogation of
- *      conversation data for newly-started long running conversations, by
- *      storing their ids in the page metadata
+ * @see WeldWebRequestCycleProcessor Which handles propogation of conversation
+ *      data for newly-started long running conversations, by storing their ids
+ *      in the page metadata
  * @author cpopetz
  * 
  */
@@ -82,18 +83,19 @@
 
       BeanManager manager = BeanManagerLookup.getBeanManager();
       
-      Conversation conversation = getInstanceByType(manager, Conversation.class);
+      ConversationImpl conversation = (ConversationImpl) getInstanceByType(manager,
+            Conversation.class);
 
-      // restore a conversation if it exists
-      if (specifiedCid != null)
+      // restore a conversation if it exists and we aren't already in it
+      if (specifiedCid != null
+            && (conversation == null || !specifiedCid.equals(conversation.getUnderlyingId())))
       {
-         // Restore this conversation
          getInstanceByType(manager, ConversationManager.class).beginOrRestoreConversation(specifiedCid);
       }
 
       // handle propagation of existing long running converstaions to new
       // targets
-      if (conversation.isLongRunning())
+      if (!conversation.isTransient())
       {
          // Note that we can't propagate conversations with other redirect
          // targets like RequestRedirectTarget through this mechanism, because
@@ -105,14 +107,14 @@
             BookmarkablePageRequestTarget bookmark = (BookmarkablePageRequestTarget) target;
             // if a cid has already been specified, don't override it
             if (!bookmark.getPageParameters().containsKey("cid"))
-               bookmark.getPageParameters().add("cid", conversation.getId());
+               bookmark.getPageParameters().add("cid", conversation.getUnderlyingId());
          }
 
          // If we have a target page, propagate the conversation to the page's
          // metadata
          if (page != null)
          {
-            page.setMetaData(WeldMetaData.CID, conversation.getId());
+            page.setMetaData(WeldMetaData.CID, conversation.getUnderlyingId());
          }
       }
 
@@ -122,7 +124,7 @@
       if (!conversationContext.isActive())
       {
          conversationContext.setBeanStore(new ConversationBeanStore(((WebRequest) request)
-               .getHttpServletRequest().getSession(), conversation.getId()));
+               .getHttpServletRequest().getSession(), conversation.getUnderlyingId()));
          conversationContext.setActive(true);
       }
    }
@@ -146,5 +148,21 @@
       }
       return beans.iterator().next();
    }
+   
+   @Override
+   public void detach()
+   {
+      super.detach();
+      ConversationContext conversationContext = Container.instance().deploymentServices().get(
+            ContextLifecycle.class).getConversationContext();
+      // cleanup and deactivate the conversation context
+      if (conversationContext.isActive())
+      {
+         ConversationManager conversationManager = getInstanceByType(BeanManagerLookup
+            .getBeanManager(), ConversationManager.class);
+         conversationManager.cleanupConversation();
+         conversationContext.setActive(false);
+      }
+   }
 
 }
\ No newline at end of file

Modified: extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldWebRequestCycleProcessor.java
===================================================================
--- extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldWebRequestCycleProcessor.java	2009-10-19 22:44:36 UTC (rev 4202)
+++ extensions/trunk/wicket/src/main/java/org/jboss/weld/wicket/WeldWebRequestCycleProcessor.java	2009-10-19 22:48:56 UTC (rev 4203)
@@ -6,16 +6,11 @@
 import org.apache.wicket.Page;
 import org.apache.wicket.RequestCycle;
 import org.apache.wicket.protocol.http.WebRequestCycleProcessor;
-import org.jboss.weld.Container;
-import org.jboss.weld.context.ContextLifecycle;
-import org.jboss.weld.context.ConversationContext;
-import org.jboss.weld.conversation.ConversationManager;
 
 /**
  * WeldWebRequestCycleProcessor is a subclass of the standard wicket
  * WebRequestCycleProcessor which saves the conversation id of any long-running
- * cornversation in wicket page metadata. It also cleans up the conversation
- * context.
+ * cornversation in wicket page metadata.
  * 
  * @author cpopetz
  * 
@@ -24,8 +19,6 @@
 {
    @Inject
    Conversation conversation;
-   @Inject
-   ConversationManager conversationManager;
    
    /**
     * If a long running conversation has been started, store its id into page
@@ -35,7 +28,7 @@
    public void respond(RequestCycle requestCycle)
    {
       super.respond(requestCycle);
-      if (conversation.isLongRunning())
+      if (!conversation.isTransient())
       {
          Page page = RequestCycle.get().getResponsePage();
          if (page != null)
@@ -44,11 +37,5 @@
          }
       }
       
-      //cleanup and deactivate the conversation context
-      conversationManager.cleanupConversation();
-      
-      ConversationContext conversationContext = Container.instance().deploymentServices().get(
-            ContextLifecycle.class).getConversationContext();
-      conversationContext.setActive(false);
    }
 }
\ No newline at end of file



More information about the weld-commits mailing list