You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ss...@apache.org on 2006/11/10 23:50:38 UTC

svn commit: r473555 - /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/MyFacesGenericPortlet.java

Author: ssilvert
Date: Fri Nov 10 14:50:37 2006
New Revision: 473555

URL: http://svn.apache.org/viewvc?view=rev&rev=473555
Log:
https://issues.apache.org/jira/browse/MYFACES-1481

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/MyFacesGenericPortlet.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/MyFacesGenericPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/MyFacesGenericPortlet.java?view=diff&rev=473555&r1=473554&r2=473555
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/MyFacesGenericPortlet.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/MyFacesGenericPortlet.java Fri Nov 10 14:50:37 2006
@@ -38,6 +38,7 @@
 import javax.portlet.PortletException;
 import javax.portlet.PortletRequest;
 import javax.portlet.PortletResponse;
+import javax.portlet.PortletSession;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.UnavailableException;
@@ -75,6 +76,12 @@
     // portlet config parameter from portlet.xml
     protected static final String DEFAULT_VIEW_SELECTOR = "default-view-selector";
 
+    // On redeploy, the session might still exist, but all values are wiped out.  
+    // This depends on the portal implementation.  So we put this flag in
+    // the session to detect if a redeploy happened.
+    protected static final String REDEPLOY_FLAG =
+        MyFacesGenericPortlet.class.getName() + ".REDEPLOY_FLAG";
+    
     protected static final String FACES_INIT_DONE =
         MyFacesGenericPortlet.class.getName() + ".FACES_INIT_DONE";
 
@@ -265,7 +272,11 @@
     protected void doView(RenderRequest request, RenderResponse response)
             throws PortletException, IOException
     {
-        facesRender(request, response);
+       try {
+          facesRender(request, response);
+       } finally {
+          renderCleanup(request);
+       }
     }
 
     /**
@@ -275,7 +286,11 @@
     protected void doEdit(RenderRequest request, RenderResponse response)
             throws PortletException, IOException
     {
-        facesRender(request, response);
+       try {
+          facesRender(request, response);
+       } finally {
+          renderCleanup(request);
+       }
     }
 
     /**
@@ -285,7 +300,18 @@
     protected void doHelp(RenderRequest request, RenderResponse response)
             throws PortletException, IOException
     {
-        facesRender(request, response);
+       try {
+         facesRender(request, response);
+       } finally {
+          renderCleanup(request);
+       }
+    }
+    
+    protected void renderCleanup(RenderRequest request)
+    {
+       PortletSession session = request.getPortletSession();
+       session.setAttribute(REDEPLOY_FLAG, "portlet was not redeployed");
+       session.removeAttribute(this.CURRENT_FACES_CONTEXT);
     }
 
     /**
@@ -364,7 +390,13 @@
 
     protected boolean sessionTimedOut(PortletRequest request)
     {
-        return request.getPortletSession(false) == null;
+       return request.getPortletSession(false) == null;
+    }
+    
+    protected boolean sessionInvalidated(PortletRequest request)
+    {
+        return  sessionTimedOut(request) ||
+               (request.getPortletSession().getAttribute(REDEPLOY_FLAG) == null);
     }
 
     protected void setPortletRequestFlag(PortletRequest request)
@@ -383,7 +415,7 @@
         setContentType(request, response);
 
         String viewId = request.getParameter(VIEW_ID);
-        if ((viewId == null) || sessionTimedOut(request))
+        if ((viewId == null) || sessionInvalidated(request))
         {
             setPortletRequestFlag(request);
             nonFacesRequest(request,  response);
@@ -398,16 +430,8 @@
             facesContext = (ServletFacesContextImpl)request.
                                                     getPortletSession().
                                                     getAttribute(CURRENT_FACES_CONTEXT);
-
-            // depending on the Portal implementation, facesContext could be
-            // null after a redeploy
-            if (facesContext == null) {
-               setPortletRequestFlag(request);
-               nonFacesRequest(request, response);
-               return;
-            }
             
-            if (facesContext.isReleased()) // processAction was not called
+            if (facesContext == null) // processAction was not called
             {
                facesContext = (ServletFacesContextImpl)facesContext(request, response);
                setViewRootOnFacesContext(facesContext, viewId);
@@ -422,12 +446,6 @@
         catch (Throwable e)
         {
             handleExceptionFromLifecycle(e);
-        }
-        finally
-        {
-           // must release the FacesContext here because it is in the 
-           // session and it might get replicated in a clustered envirnoment
-           if (facesContext != null) facesContext.release();
         }
     }