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/05/13 16:15:15 UTC

svn commit: r774378 - in /incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans: jsf/WebBeansPhaseListener.java util/JSFUtil.java

Author: gerdogdu
Date: Wed May 13 14:15:15 2009
New Revision: 774378

URL: http://svn.apache.org/viewvc?rev=774378&view=rev
Log:
Update for M2 after testing. Correction of some bugs in the context tests.

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

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=774378&r1=774377&r2=774378&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 Wed May 13 14:15:15 2009
@@ -15,7 +15,6 @@
 
 import javax.context.ConversationScoped;
 import javax.faces.component.UIViewRoot;
-import javax.faces.component.html.HtmlInputHidden;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
@@ -35,6 +34,8 @@
     private static WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansPhaseListener.class);
 
     private static ConversationManager conversationManager = ConversationManager.getInstance();
+    
+    public static final String CONVERSATION_ATTR_ID = "javax_webbeans_ConversationId";
 
     private ConversationImpl conversation = null;
 
@@ -50,6 +51,7 @@
                 if (cid == null)
                 {
                     logger.info("Create new transitional conversation for non-faces request with view id : " + JSFUtil.getViewId());
+                    
                     conversation = (ConversationImpl) conversationManager.createNewConversation();
 
                     ContextFactory.initConversationContext(null);
@@ -79,12 +81,21 @@
                 logger.info("Postback JSF Request for view id : " + JSFUtil.getViewId());
 
                 UIViewRoot viewRoot = JSFUtil.getViewRoot();
-                HtmlInputHidden conversationId = (HtmlInputHidden) viewRoot.findComponent("javax_webbeans_ConversationId");
+                
+                Object attr = viewRoot.getAttributes().get(CONVERSATION_ATTR_ID);
 
+                String conversationId = null;
+                
+                if(attr != null)
+                {
+                    conversationId = attr.toString();
+                }
+                
                 if (conversationId != null)
                 {
                     // look long running conversation if exist
-                    conversation = (ConversationImpl) conversationManager.getConversation(conversationId.getValue().toString());
+                    conversation = (ConversationImpl) conversationManager.getConversation(conversationId);
+                    
                     ContextFactory.initConversationContext(conversationManager.getConversationContext(conversation));
 
                 }
@@ -93,6 +104,7 @@
                 else
                 {
                     logger.info("Create new transient conversation for JSF postback view id : " + JSFUtil.getViewId());
+                    
                     conversation = (ConversationImpl) conversationManager.createNewConversation();
 
                     ContextFactory.initConversationContext(null);
@@ -108,6 +120,7 @@
             if (conversation.isLongRunning())
             {
                 logger.info("Conversation with id : " + conversation.getId() + " is marked as long running conversation");
+                
                 context.setActive(false);
             }
 
@@ -115,7 +128,8 @@
             else
             {
                 logger.info("Destroying the conversation context for view id : " + JSFUtil.getViewId());
-                context.destroy();                                    
+                
+                ContextFactory.destroyConversationContext();                                    
             }
 
         }
@@ -124,17 +138,20 @@
 
     public void beforePhase(PhaseEvent phaseEvent)
     {
-        if (phaseEvent.getPhaseId().equals(PhaseId.APPLY_REQUEST_VALUES))
+        if (phaseEvent.getPhaseId().equals(PhaseId.RESTORE_VIEW))
+        {            
+            ContextFactory.initConversationContext(null);            
+        }
+        
+        else if(phaseEvent.getPhaseId().equals(PhaseId.APPLY_REQUEST_VALUES))
         {
-            ConversationContext context = (ConversationContext) ManagerImpl.getManager().getContext(ConversationScoped.class);
 
             if (JSFUtil.isPostBack())
             {
-                logger.info("Activating the conversation context for view id : " + JSFUtil.getViewId());
-                context.setActive(true);
+                logger.info("Activating the conversation context for view id : " + JSFUtil.getViewId());                
 
                 conversation.updateTimeOut();
-            }
+            }            
         }
 
         else if (phaseEvent.getPhaseId().equals(PhaseId.RENDER_RESPONSE))
@@ -152,32 +169,14 @@
             if (conversation.isLongRunning())
             {
                 UIViewRoot viewRoot = JSFUtil.getViewRoot();
-
-                HtmlInputHidden hidden = (HtmlInputHidden) viewRoot.findComponent("javax_webbeans_ConversationId");
-
-                if (hidden != null)
-                {
-                    viewRoot.getChildren().remove(hidden);
-                }
-
-                hidden = (HtmlInputHidden) JSFUtil.getApplication().createComponent(HtmlInputHidden.COMPONENT_TYPE);
-                hidden.setValue(conversation.getId());
-                hidden.setId("javax_webbeans_ConversationId");
-
-                viewRoot.getChildren().add(hidden);
+                
+                viewRoot.getAttributes().put(CONVERSATION_ATTR_ID, conversation.getId());
             }
             else
             {
-                //Remove the hidden component
                 UIViewRoot viewRoot = JSFUtil.getViewRoot();
-
-                HtmlInputHidden hidden = (HtmlInputHidden) viewRoot.findComponent("javax_webbeans_ConversationId");
-
-                if (hidden != null)
-                {
-                    viewRoot.getChildren().remove(hidden);
-                }
                 
+                viewRoot.getAttributes().remove(CONVERSATION_ATTR_ID);                
             }
         }
 

Modified: incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/util/JSFUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/util/JSFUtil.java?rev=774378&r1=774377&r2=774378&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/util/JSFUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/util/JSFUtil.java Wed May 13 14:15:15 2009
@@ -17,11 +17,12 @@
 import javax.faces.application.FacesMessage;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIViewRoot;
-import javax.faces.component.html.HtmlInputHidden;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.servlet.http.HttpSession;
 
+import org.apache.webbeans.jsf.WebBeansPhaseListener;
+
 public final class JSFUtil
 {
     private JSFUtil()
@@ -88,13 +89,17 @@
     public static String getConversationId()
     {
         UIViewRoot viewRoot = JSFUtil.getViewRoot();
-        HtmlInputHidden conversationId = (HtmlInputHidden) viewRoot.findComponent("javax_webbeans_ConversationId");
-
-        if (conversationId != null)
+        
+        if(viewRoot != null)
         {
-            return conversationId.getValue().toString();
-        }
+            Object conversationId = viewRoot.getAttributes().get(WebBeansPhaseListener.CONVERSATION_ATTR_ID);
 
+            if (conversationId != null)
+            {
+                return conversationId.toString();
+            }            
+        }
+        
         return null;
     }
 }