This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 9006e03  OWB-1295
9006e03 is described below

commit 9006e03f9ef61524918e06f000593abec12a1e96
Author: Thomas Andraschko <[email protected]>
AuthorDate: Mon Jul 22 10:34:25 2019 +0200

    OWB-1295
---
 .../webbeans/jsf/ConversationAwareViewHandler.java | 46 +++++++++++++++++-----
 1 file changed, 37 insertions(+), 9 deletions(-)

diff --git 
a/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java
 
b/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java
index 26fe826..64f434d 100644
--- 
a/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java
+++ 
b/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java
@@ -20,14 +20,16 @@ package org.apache.webbeans.jsf;
 
 import java.util.List;
 import java.util.Map;
+import javax.enterprise.context.ContextNotActiveException;
 
 import javax.enterprise.context.Conversation;
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.context.spi.Context;
 import javax.faces.application.ViewHandler;
 import javax.faces.application.ViewHandlerWrapper;
 import javax.faces.context.FacesContext;
 
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.conversation.ConversationManager;
 
 public class ConversationAwareViewHandler extends ViewHandlerWrapper
 {
@@ -53,11 +55,23 @@ public class ConversationAwareViewHandler extends 
ViewHandlerWrapper
         
         String url = delegate.getActionURL(context, viewId);
 
-        ConversationManager conversationManager = 
WebBeansContext.getInstance().getConversationManager();
-        Conversation conversation = 
conversationManager.getConversationBeanReference();
-        if (conversation != null && !conversation.isTransient())
+        try
         {
-            url = JSFUtil.getRedirectViewIdWithCid(url, conversation.getId());
+            WebBeansContext webBeansContext = 
WebBeansContext.currentInstance();
+            
+            Context conversationContext = 
webBeansContext.getBeanManagerImpl().getContext(ConversationScoped.class);
+            if (conversationContext.isActive())
+            {
+                Conversation conversation = 
webBeansContext.getConversationManager().getConversationBeanReference();
+                if (conversation != null && !conversation.isTransient())
+                {
+                    url = JSFUtil.getRedirectViewIdWithCid(url, 
conversation.getId());
+                }
+            }
+        }
+        catch (ContextNotActiveException e)
+        {
+            // ignore
         }
 
         return url;
@@ -97,12 +111,26 @@ public class ConversationAwareViewHandler extends 
ViewHandlerWrapper
                 return url;
             }
         }
-        ConversationManager conversationManager = 
WebBeansContext.getInstance().getConversationManager();
-        Conversation conversation = 
conversationManager.getConversationBeanReference();
-        if (conversation != null && !conversation.isTransient())
+        
+        try
+        {
+            WebBeansContext webBeansContext = 
WebBeansContext.currentInstance();
+            
+            Context conversationContext = 
webBeansContext.getBeanManagerImpl().getContext(ConversationScoped.class);
+            if (conversationContext.isActive())
+            {
+                Conversation conversation = 
webBeansContext.getConversationManager().getConversationBeanReference();
+                if (conversation != null && !conversation.isTransient())
+                {
+                    url = JSFUtil.getRedirectViewIdWithCid(url, 
conversation.getId());
+                }
+            }
+        }
+        catch (ContextNotActiveException e)
         {
-            url = JSFUtil.getRedirectViewIdWithCid(url, conversation.getId());
+            // ignore
         }
+
         return url;
     }
     

Reply via email to