You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2013/10/18 04:01:42 UTC
svn commit: r1533310 -
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/ManagedBeanDestroyerListener.java
Author: lu4242
Date: Fri Oct 18 02:01:42 2013
New Revision: 1533310
URL: http://svn.apache.org/r1533310
Log:
MYFACES-3747 Implement new JSF 2.2 ViewScope specification (fix PreDestroy case on session timeout)
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/ManagedBeanDestroyerListener.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/ManagedBeanDestroyerListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/ManagedBeanDestroyerListener.java?rev=1533310&r1=1533309&r2=1533310&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/ManagedBeanDestroyerListener.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/ManagedBeanDestroyerListener.java Fri Oct 18 02:01:42 2013
@@ -19,6 +19,9 @@
package org.apache.myfaces.webapp;
import java.util.Enumeration;
+import javax.faces.context.ExceptionHandler;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
@@ -36,6 +39,10 @@ import javax.servlet.http.HttpSessionEve
import javax.servlet.http.HttpSessionListener;
import org.apache.myfaces.config.ManagedBeanDestroyer;
+import org.apache.myfaces.context.ReleaseableExternalContext;
+import org.apache.myfaces.context.servlet.StartupFacesContextImpl;
+import org.apache.myfaces.context.servlet.StartupServletExternalContextImpl;
+import org.apache.myfaces.shared.context.ExceptionHandlerImpl;
import org.apache.myfaces.spi.ViewScopeProvider;
/**
@@ -145,7 +152,30 @@ public class ManagedBeanDestroyerListene
// with attributeRemoved, but on cdi a wrapper is used instead, avoiding the problem.
if (_viewScopeHandler != null)
{
- _viewScopeHandler.onSessionDestroyed();
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ if (facesContext != null)
+ {
+ _viewScopeHandler.onSessionDestroyed();
+ }
+ else
+ {
+ // In case no FacesContext is available, we are on session invalidation
+ // through timeout. In that case, create a dummy FacesContext for this one
+ // like the one used in startup or shutdown and invoke the destroy method.
+ try
+ {
+ ServletContext servletContext = event.getSession().getServletContext();
+ ExternalContext externalContext = new StartupServletExternalContextImpl(servletContext, false);
+ ExceptionHandler exceptionHandler = new ExceptionHandlerImpl();
+ facesContext = new StartupFacesContextImpl(externalContext,
+ (ReleaseableExternalContext) externalContext, exceptionHandler, false);
+ _viewScopeHandler.onSessionDestroyed();
+ }
+ finally
+ {
+ facesContext.release();
+ }
+ }
}
}