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 2010/08/09 18:57:04 UTC
svn commit: r983733 -
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java
Author: lu4242
Date: Mon Aug 9 16:57:04 2010
New Revision: 983733
URL: http://svn.apache.org/viewvc?rev=983733&view=rev
Log:
MYFACES-2870 StartupServletContextListener could be called twice on init and destroy
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java?rev=983733&r1=983732&r2=983733&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java Mon Aug 9 16:57:04 2010
@@ -92,63 +92,59 @@ public class StartupServletContextListen
}
_servletContext = event.getServletContext();
- if (_facesInitializer == null)
- {
- _facesInitializer = FacesInitializerFactory.getFacesInitializer(_servletContext);
- }
-
- // Create startup FacesContext before initializing
- FacesContext facesContext = _facesInitializer.initStartupFacesContext(_servletContext);
-
Boolean b = (Boolean) _servletContext.getAttribute(FACES_INIT_DONE);
if (b == null || b.booleanValue() == false)
{
+ if (_facesInitializer == null)
+ {
+ _facesInitializer = FacesInitializerFactory.getFacesInitializer(_servletContext);
+ }
+
+ // Create startup FacesContext before initializing
+ FacesContext facesContext = _facesInitializer.initStartupFacesContext(_servletContext);
+
dispatchInitializationEvent(event, FACES_INIT_PHASE_PREINIT);
_facesInitializer.initFaces(_servletContext);
dispatchInitializationEvent(event, FACES_INIT_PHASE_POSTINIT);
_servletContext.setAttribute(FACES_INIT_DONE, Boolean.TRUE);
+
+ // call contextInitialized on ManagedBeanDestroyerListener
+ _detroyerListener.contextInitialized(event);
+
+ //Destroy startup FacesContext
+ _facesInitializer.destroyStartupFacesContext(facesContext);
}
else
{
log.info("MyFaces already initialized");
}
-
- // call contextInitialized on ManagedBeanDestroyerListener
- _detroyerListener.contextInitialized(event);
-
- //Destroy startup FacesContext
- _facesInitializer.destroyStartupFacesContext(facesContext);
}
public void contextDestroyed(ServletContextEvent event)
{
- // Create startup FacesContext before start undeploy
- FacesContext facesContext = null;
if (_facesInitializer != null && _servletContext != null)
{
- facesContext = _facesInitializer.initShutdownFacesContext(_servletContext);
- }
-
- dispatchInitializationEvent(event, FACES_INIT_PHASE_PREDESTROY);
- // call contextDestroyed on ManagedBeanDestroyerListener to destroy the attributes
- _detroyerListener.contextDestroyed(event);
+ // Create startup FacesContext before start undeploy
+ FacesContext facesContext = _facesInitializer.initShutdownFacesContext(_servletContext);
+
+ dispatchInitializationEvent(event, FACES_INIT_PHASE_PREDESTROY);
+ // call contextDestroyed on ManagedBeanDestroyerListener to destroy the attributes
+ _detroyerListener.contextDestroyed(event);
- if (_facesInitializer != null && _servletContext != null)
- {
_facesInitializer.destroyFaces(_servletContext);
+
+ // Destroy startup FacesContext, but note we do before publish postdestroy event on
+ // plugins and before release factories.
+ if (facesContext != null)
+ {
+ _facesInitializer.destroyShutdownFacesContext(facesContext);
+ }
+
+ FactoryFinder.releaseFactories();
+ DiscoverSingleton.release(); //clears EnvironmentCache and prevents leaking classloader references
+ dispatchInitializationEvent(event, FACES_INIT_PHASE_POSTDESTROY);
}
- // Destroy startup FacesContext, but note we do before publish postdestroy event on
- // plugins and before release factories.
- if (facesContext != null)
- {
- _facesInitializer.destroyShutdownFacesContext(facesContext);
- }
-
- FactoryFinder.releaseFactories();
- DiscoverSingleton.release(); //clears EnvironmentCache and prevents leaking classloader references
- dispatchInitializationEvent(event, FACES_INIT_PHASE_POSTDESTROY);
-
_servletContext = null;
}