You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/11/20 20:06:19 UTC

svn commit: r882680 - in /incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf: WebBeansJSFFilter.java WebBeansPhaseListener.java

Author: gerdogdu
Date: Fri Nov 20 19:05:51 2009
New Revision: 882680

URL: http://svn.apache.org/viewvc?rev=882680&view=rev
Log:
Update WebBeansPhaseListener code.

Modified:
    incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansJSFFilter.java
    incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java

Modified: incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansJSFFilter.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansJSFFilter.java?rev=882680&r1=882679&r2=882680&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansJSFFilter.java (original)
+++ incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansJSFFilter.java Fri Nov 20 19:05:51 2009
@@ -62,9 +62,7 @@
                 {
 
                     if (!conversation.isTransient())
-                    {
-                        WebBeansPhaseListener.fromRedirect.set(Boolean.TRUE);
-                        
+                    {                        
                         path = JSFUtil.getRedirectViewIdWithCid(location, conversation.getId());
                     }
                 }

Modified: incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java?rev=882680&r1=882679&r2=882680&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java (original)
+++ incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java Fri Nov 20 19:05:51 2009
@@ -13,6 +13,7 @@
  */
 package org.apache.webbeans.jsf;
 
+import javax.enterprise.context.Conversation;
 import javax.faces.component.UIViewRoot;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
@@ -42,15 +43,8 @@
     public static final String CONVERSATION_ATTR_ID = "javax_webbeans_ConversationId";
 
     /**current conversation if exist*/
-    private ConversationImpl conversation = null;
-    
-    public static ThreadLocal<Boolean> fromRedirect = new ThreadLocal<Boolean>();
-
-    static
-    {
-        fromRedirect.set(Boolean.FALSE);
-    }
-    
+    private static final ThreadLocal<ConversationImpl> conversation = new ThreadLocal<ConversationImpl>();
+        
     /**
      * {@inheritDoc}
      */
@@ -67,7 +61,7 @@
                 {
                     logger.info("Create new transitional conversation for non-faces request with view id : " + JSFUtil.getViewId());
                     
-                    conversation = (ConversationImpl) conversationManager.createNewConversationInstance();                    
+                    setConversation((ConversationImpl) conversationManager.createNewConversationInstance());                    
 
                     ContextFactory.initConversationContext(null);
 
@@ -76,13 +70,13 @@
                 {
                     logger.info("Propogation of the conversation for non-faces request with cid=" + cid + " for view : " + JSFUtil.getViewId());
                     
-                    conversation = (ConversationImpl) conversationManager.getConversation(cid, JSFUtil.getSession().getId());
+                    setConversation((ConversationImpl) conversationManager.getConversation(cid, JSFUtil.getSession().getId()));
 
                     // can not restore conversation, create new transitional
-                    if (conversation == null)
+                    if (getConversation() == null)
                     {
                         logger.info("Propogated conversation for non-faces request can not be restored for view id : " + JSFUtil.getViewId() + ". Creates new transitional conversation");
-                        conversation = (ConversationImpl) conversationManager.createNewConversationInstance();
+                        setConversation((ConversationImpl) conversationManager.createNewConversationInstance());
 
                         ContextFactory.initConversationContext(null);                        
                     }
@@ -90,13 +84,8 @@
                     {
                         logger.info("Conversation is restored for non-faces request with cid=" + cid + " for view id : " + JSFUtil.getViewId());
                         
-                        ContextFactory.initConversationContext(conversationManager.getConversationContext(conversation));
+                        ContextFactory.initConversationContext(conversationManager.getConversationContext(getConversation()));
                     }
-                }
-                
-                if(fromRedirect.get() != null && fromRedirect.get() && conversation.getId() != null)
-                {
-                    this.conversation.setTransient(false);  
                 }                
             }
             else
@@ -117,13 +106,13 @@
                 if (conversationId != null)
                 {
                     // look long running conversation if exist
-                    conversation = (ConversationImpl) conversationManager.getConversation(conversationId, JSFUtil.getSession().getId());
+                    setConversation((ConversationImpl) conversationManager.getConversation(conversationId, JSFUtil.getSession().getId()));
                     
-                    if(conversation != null)
+                    if(getConversation() != null)
                     {
                         logger.info("Conversation is restored for JSF postback with cid=" + conversationId + " for view id : " + JSFUtil.getViewId());
                         
-                        ContextFactory.initConversationContext(conversationManager.getConversationContext(conversation));   
+                        ContextFactory.initConversationContext(conversationManager.getConversationContext(getConversation()));   
                     }
                     else
                     {
@@ -140,7 +129,7 @@
                 {
                     logger.info("Create new transient conversation for JSF postback view id : " + JSFUtil.getViewId());
                     
-                    conversation = (ConversationImpl) conversationManager.createNewConversationInstance();
+                    setConversation((ConversationImpl) conversationManager.createNewConversationInstance());
 
                     ContextFactory.initConversationContext(null);
                 }
@@ -149,18 +138,20 @@
 
         else if (phaseEvent.getPhaseId().equals(PhaseId.RENDER_RESPONSE))
         {
-            if (conversation.isTransient())
+            if (getConversation().isTransient())
             {
-                logger.info("Destroying the conversation context with cid="+ conversation.getId() + " for view id : " + JSFUtil.getViewId());
+                logger.info("Destroying the conversation context with cid="+ getConversation().getId() + " for view id : " + JSFUtil.getViewId());
                 
-                this.conversation.end();
+                getConversation().end();
                 
                 ContextFactory.destroyConversationContext();                                                    
             }
             else
             {
-                conversation.updateTimeOut();
+                getConversation().updateTimeOut();
             }
+            
+            conversation.remove();
         }
     }
 
@@ -176,15 +167,15 @@
         
         else if (phaseEvent.getPhaseId().equals(PhaseId.RENDER_RESPONSE))
         {
-            if (!conversation.isTransient())
+            if (!getConversation().isTransient())
             {
-                logger.info("Saving conversation with cid=" + this.conversation.getId() + " for view " + JSFUtil.getViewId());
+                logger.info("Saving conversation with cid=" + getConversation().getId() + " for view " + JSFUtil.getViewId());
                 
                 UIViewRoot viewRoot = JSFUtil.getViewRoot();
                 
-                viewRoot.getAttributes().put(CONVERSATION_ATTR_ID, conversation.getId());
+                viewRoot.getAttributes().put(CONVERSATION_ATTR_ID, getConversation().getId());
                 
-                JSFUtil.getExternalContext().getRequestMap().put("cid",conversation.getId());
+                JSFUtil.getExternalContext().getRequestMap().put("cid",getConversation().getId());
             }
             else
             {
@@ -195,6 +186,16 @@
         }
 
     }
+    
+    public ConversationImpl getConversation()
+    {
+        return conversation.get();
+    }
+    
+    public void setConversation(ConversationImpl conversationImpl)
+    {
+        conversation.set(conversationImpl);
+    }
 
     public PhaseId getPhaseId()
     {