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/06/24 17:22:25 UTC
svn commit: r957581 - in
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: context/servlet/
webapp/
Author: lu4242
Date: Thu Jun 24 15:22:24 2010
New Revision: 957581
URL: http://svn.apache.org/viewvc?rev=957581&view=rev
Log:
MYFACES-2730 FacesContext not available on application startup
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/StartupFacesContextImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/StartupServletExternalContextImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/MyFacesServlet.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java?rev=957581&r1=957580&r2=957581&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java Thu Jun 24 15:22:24 2010
@@ -19,12 +19,9 @@
package org.apache.myfaces.context.servlet;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.net.URLEncoder;
import java.security.Principal;
import java.util.ArrayList;
@@ -33,11 +30,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
import java.util.logging.Logger;
import javax.faces.FacesException;
-import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.Flash;
import javax.faces.context.PartialResponseWriter;
@@ -52,7 +47,6 @@ import javax.servlet.http.HttpServletReq
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import org.apache.myfaces.context.ReleaseableExternalContext;
import org.apache.myfaces.shared_impl.context.flash.FlashImpl;
import org.apache.myfaces.util.EnumerationIterator;
@@ -63,21 +57,18 @@ import org.apache.myfaces.util.Enumerati
* @author Anton Koinov
* @version $Revision$ $Date$
*/
-public final class ServletExternalContextImpl extends ExternalContext implements ReleaseableExternalContext
+public final class ServletExternalContextImpl extends ServletExternalContextImplBase
{
//private static final Log log = LogFactory.getLog(ServletExternalContextImpl.class);
private static final Logger log = Logger.getLogger(ServletExternalContextImpl.class.getName());
- private static final String INIT_PARAMETER_MAP_ATTRIBUTE = InitParameterMap.class.getName();
private static final String URL_PARAM_SEPERATOR="&";
private static final String URL_QUERY_SEPERATOR="?";
private static final String URL_FRAGMENT_SEPERATOR="#";
private static final String URL_NAME_VALUE_PAIR_SEPERATOR="=";
- private ServletContext _servletContext;
private ServletRequest _servletRequest;
private ServletResponse _servletResponse;
- private Map<String, Object> _applicationMap;
private Map<String, Object> _sessionMap;
private Map<String, Object> _requestMap;
private Map<String, String> _requestParameterMap;
@@ -85,19 +76,19 @@ public final class ServletExternalContex
private Map<String, String> _requestHeaderMap;
private Map<String, String[]> _requestHeaderValuesMap;
private Map<String, Object> _requestCookieMap;
- private Map<String, String> _initParameterMap;
private HttpServletRequest _httpServletRequest;
private HttpServletResponse _httpServletResponse;
private String _requestServletPath;
private String _requestPathInfo;
- public ServletExternalContextImpl(final ServletContext servletContext, final ServletRequest servletRequest,
+ public ServletExternalContextImpl(final ServletContext servletContext,
+ final ServletRequest servletRequest,
final ServletResponse servletResponse)
{
- _servletContext = servletContext;
+ super(servletContext); // initialize ServletExternalContextImplBase
+
_servletRequest = servletRequest;
_servletResponse = servletResponse;
- _applicationMap = null;
_sessionMap = null;
_requestMap = null;
_requestParameterMap = null;
@@ -105,7 +96,6 @@ public final class ServletExternalContex
_requestHeaderMap = null;
_requestHeaderValuesMap = null;
_requestCookieMap = null;
- _initParameterMap = null;
_httpServletRequest = isHttpServletRequest(servletRequest) ? (HttpServletRequest) servletRequest : null;
_httpServletResponse = isHttpServletResponse(servletResponse) ? (HttpServletResponse) servletResponse : null;
@@ -121,10 +111,10 @@ public final class ServletExternalContex
public void release()
{
- _servletContext = null;
+ super.release(); // releases fields on ServletExternalContextImplBase
+
_servletRequest = null;
_servletResponse = null;
- _applicationMap = null;
_sessionMap = null;
_requestMap = null;
_requestParameterMap = null;
@@ -132,7 +122,6 @@ public final class ServletExternalContex
_requestHeaderMap = null;
_requestHeaderValuesMap = null;
_requestCookieMap = null;
- _initParameterMap = null;
_httpServletRequest = null;
_httpServletResponse = null;
}
@@ -145,12 +134,6 @@ public final class ServletExternalContex
}
@Override
- public Object getContext()
- {
- return _servletContext;
- }
-
- @Override
public Object getRequest()
{
return _servletRequest;
@@ -202,16 +185,6 @@ public final class ServletExternalContex
}
@Override
- public Map<String, Object> getApplicationMap()
- {
- if (_applicationMap == null)
- {
- _applicationMap = new ApplicationMap(_servletContext);
- }
- return _applicationMap;
- }
-
- @Override
public Map<String, Object> getSessionMap()
{
if (_sessionMap == null)
@@ -330,56 +303,12 @@ public final class ServletExternalContex
}
@Override
- public String getInitParameter(final String s)
- {
- return _servletContext.getInitParameter(s);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public Map<String, String> getInitParameterMap()
- {
- if (_initParameterMap == null)
- {
- // We cache it as an attribute in ServletContext itself (is this circular reference a problem?)
- if ((_initParameterMap = (Map<String, String>) _servletContext.getAttribute(INIT_PARAMETER_MAP_ATTRIBUTE)) == null)
- {
- _initParameterMap = new InitParameterMap(_servletContext);
- _servletContext.setAttribute(INIT_PARAMETER_MAP_ATTRIBUTE, _initParameterMap);
- }
- }
- return _initParameterMap;
- }
-
- @Override
- public String getMimeType(String file)
- {
- checkNull(file, "file");
- return _servletContext.getMimeType(file);
- }
-
- @Override
public String getRequestScheme()
{
return _servletRequest.getScheme();
}
@Override
- @SuppressWarnings("unchecked")
- public Set<String> getResourcePaths(final String path)
- {
- checkNull(path, "path");
- return _servletContext.getResourcePaths(path);
- }
-
- @Override
- public InputStream getResourceAsStream(final String path)
- {
- checkNull(path, "path");
- return _servletContext.getResourceAsStream(path);
- }
-
- @Override
public String encodeActionURL(final String url)
{
checkNull(url, "url");
@@ -473,13 +402,6 @@ public final class ServletExternalContex
}
@Override
- public String getRealPath(String path)
- {
- checkNull(path, "path");
- return _servletContext.getRealPath(path);
- }
-
- @Override
public String getRemoteUser()
{
checkHttpServletRequest();
@@ -522,21 +444,6 @@ public final class ServletExternalContex
}
@Override
- public void log(final String message)
- {
- checkNull(message, "message");
- _servletContext.log(message);
- }
-
- @Override
- public void log(final String message, final Throwable exception)
- {
- checkNull(message, "message");
- checkNull(exception, "exception");
- _servletContext.log(message, exception);
- }
-
- @Override
public void redirect(final String url) throws IOException
{
FacesContext facesContext = FacesContext.getCurrentInstance();
@@ -608,13 +515,6 @@ public final class ServletExternalContex
return new EnumerationIterator(_httpServletRequest.getLocales());
}
- @Override
- public URL getResource(final String path) throws MalformedURLException
- {
- checkNull(path, "path");
- return _servletContext.getResource(path);
- }
-
/**
* @since JSF 1.2
* @param request
@@ -731,14 +631,6 @@ public final class ServletExternalContex
_httpServletResponse.setStatus(statusCode);
}
- private void checkNull(final Object o, final String param)
- {
- if (o == null)
- {
- throw new NullPointerException(param + " can not be null.");
- }
- }
-
private void checkHttpServletRequest()
{
if (_httpServletRequest == null)
@@ -816,11 +708,6 @@ public final class ServletExternalContex
_httpServletResponse.addHeader(name, value);
}
- @Override
- public String getContextName() {
- return _servletContext.getServletContextName();
- }
-
private String encodeURL(String baseUrl, Map<String, List<String>> parameters)
{
checkNull(baseUrl, "url");
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/StartupFacesContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/StartupFacesContextImpl.java?rev=957581&r1=957580&r2=957581&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/StartupFacesContextImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/StartupFacesContextImpl.java Thu Jun 24 15:22:24 2010
@@ -18,17 +18,18 @@
*/
package org.apache.myfaces.context.servlet;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import javax.el.ELContext;
+import javax.el.ELContextEvent;
+import javax.el.ELContextListener;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import javax.faces.application.FacesMessage;
-import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExternalContext;
@@ -38,7 +39,10 @@ import javax.faces.context.ResponseStrea
import javax.faces.context.ResponseWriter;
import javax.faces.event.PhaseId;
import javax.faces.render.RenderKit;
-import javax.servlet.ServletContext;
+import javax.faces.render.RenderKitFactory;
+
+import org.apache.myfaces.context.ReleaseableExternalContext;
+import org.apache.myfaces.el.unified.FacesELContext;
/**
* A FacesContext implementation which will be set as the current instance
@@ -52,18 +56,33 @@ public class StartupFacesContextImpl ext
{
public static final String EXCEPTION_TEXT = "This method is not supported during ";
-
- private boolean _startup;
- private boolean _released = false;
+
private Application _application;
- private StartupServletExternalContextImpl _externalContext; // use real type for call to release()
+ private ExternalContext _externalContext;
+ private ReleaseableExternalContext _defaultExternalContext;
private UIViewRoot _viewRoot;
+ private RenderKitFactory _renderKitFactory;
+ private boolean _released = false;
+ private ELContext _elContext;
+ private Map<Object, Object> _attributes = null;
+ private boolean _processingEvents = true;
+ private ExceptionHandler _exceptionHandler = null;
+ // Variables used to cache values
+ private RenderKit _cachedRenderKit = null;
+ private String _cachedRenderKitId = null;
- public StartupFacesContextImpl(boolean startup, ServletContext servletContext)
+ private boolean _startup;
+
+ public StartupFacesContextImpl(
+ ExternalContext externalContext,
+ ReleaseableExternalContext defaultExternalContext,
+ ExceptionHandler exceptionHandler,
+ boolean startup)
{
_startup = startup;
- _externalContext = new StartupServletExternalContextImpl(startup, servletContext);
-
+ _externalContext = externalContext;
+ _defaultExternalContext = defaultExternalContext;
+ _exceptionHandler = exceptionHandler;
// this FacesContext impl is now the current instance
// note that because this method is protected, it has to be called from here
FacesContext.setCurrentInstance(this);
@@ -71,6 +90,26 @@ public class StartupFacesContextImpl ext
// ~ Methods which are valid to be called during startup and shutdown------
+ @Override
+ public ExceptionHandler getExceptionHandler()
+ {
+ return _exceptionHandler;
+ }
+
+ /**
+ * If called during application startup or shutdown, this method returns an
+ * ExternalContext instance with the special behaviors indicated in the
+ * javadoc for that class. Methods document as being valid to call during
+ * application startup or shutdown must be supported.
+ */
+ @Override
+ public final ExternalContext getExternalContext()
+ {
+ assertNotReleased();
+
+ return (ExternalContext) _externalContext;
+ }
+
/**
* If called during application startup or shutdown, this method returns
* the correct current Application instance.
@@ -88,19 +127,35 @@ public class StartupFacesContextImpl ext
return _application;
}
-
- /**
- * If called during application startup or shutdown, this method returns an
- * ExternalContext instance with the special behaviors indicated in the
- * javadoc for that class. Methods document as being valid to call during
- * application startup or shutdown must be supported.
- */
+
@Override
- public ExternalContext getExternalContext()
+ public final RenderKit getRenderKit()
{
assertNotReleased();
+
+ if (getViewRoot() == null)
+ {
+ return null;
+ }
+
+ String renderKitId = getViewRoot().getRenderKitId();
+
+ if (renderKitId == null)
+ {
+ return null;
+ }
- return _externalContext;
+ if (_cachedRenderKitId == null || !renderKitId.equals(_cachedRenderKitId))
+ {
+ _cachedRenderKitId = renderKitId;
+ if (_renderKitFactory == null)
+ {
+ _renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ }
+ _cachedRenderKit = _renderKitFactory.getRenderKit(this, renderKitId);
+ }
+
+ return _cachedRenderKit;
}
/**
@@ -108,213 +163,297 @@ public class StartupFacesContextImpl ext
* new UIViewRoot with its locale set to Locale.getDefault().
*/
@Override
- public UIViewRoot getViewRoot()
+ public final void setViewRoot(final UIViewRoot viewRoot)
{
assertNotReleased();
-
- if (_viewRoot == null)
+
+ if (viewRoot == null)
{
- _viewRoot = new UIViewRoot();
- _viewRoot.setLocale(Locale.getDefault());
+ throw new NullPointerException("viewRoot");
}
-
+ // If the current UIViewRoot is non-null, and calling equals() on the argument root, passing the current UIViewRoot returns false
+ // the clear method must be called on the Map returned from UIViewRoot.getViewMap().
+ if (_viewRoot != null && !_viewRoot.equals(viewRoot))
+ {
+ //call getViewMap(false) to prevent unnecessary map creation
+ Map<String, Object> viewMap = _viewRoot.getViewMap(false);
+ if (viewMap != null)
+ {
+ viewMap.clear();
+ }
+ }
+ _viewRoot = viewRoot;
+ }
+
+ @Override
+ public final UIViewRoot getViewRoot()
+ {
+ assertNotReleased();
+
return _viewRoot;
}
-
+
@Override
public void release()
{
assertNotReleased();
-
- _externalContext.release();
+
+ if (_defaultExternalContext != null)
+ {
+ _defaultExternalContext.release();
+ _defaultExternalContext = null;
+ }
_externalContext = null;
+
+ /*
+ * Spec JSF 2 section getAttributes when release is called the attributes map must!!! be cleared!
+ *
+ * (probably to trigger some clearance methods on possible added entries before nullifying everything)
+ */
+ if (_attributes != null)
+ {
+ _attributes.clear();
+ _attributes = null;
+ }
+
_application = null;
_viewRoot = null;
-
+ _cachedRenderKit = null;
+ _cachedRenderKitId = null;
+
_released = true;
FacesContext.setCurrentInstance(null);
}
-
- // Note that isProjectStage() also is valid to be called, but this method
- // is already implemented in FacesContext class.
-
- // ~ Methods which can be called during startup and shutdown, but are not
- // officially supported by the spec--------------------------------------
-
- @Override
- public boolean isProcessingEvents()
- {
- return true;
- }
-
- // ~ Methods which are unsupported during startup and shutdown-------------
-
+
@Override
- public void addMessage(String clientId, FacesMessage message)
+ public void setExceptionHandler(ExceptionHandler exceptionHandler)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ _exceptionHandler = exceptionHandler;
}
@Override
- public Iterator<String> getClientIdsWithMessages()
+ public final ELContext getELContext()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
- }
+ assertNotReleased();
- @Override
- public Severity getMaximumSeverity()
- {
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
- }
+ if (_elContext != null)
+ {
+ return _elContext;
+ }
- @Override
- public Iterator<FacesMessage> getMessages()
- {
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ _elContext = new FacesELContext(getApplication().getELResolver(), this);
+
+ ELContextEvent event = new ELContextEvent(_elContext);
+ for (ELContextListener listener : getApplication().getELContextListeners())
+ {
+ listener.contextCreated(event);
+ }
+
+ return _elContext;
}
+ /**
+ * Returns a mutable map of attributes associated with this faces context when
+ * {@link javax.faces.context.FacesContext.release} is called the map must be cleared!
+ *
+ * Note this map is not associated with the request map the request map still is accessible via the
+ * {@link javax.faces.context.FacesContext.getExternalContext.getRequestMap} method!
+ *
+ * Also the scope is different to the request map, this map has the scope of the context, and is cleared once the
+ * release method on the context is called!
+ *
+ * Also the map does not cause any events according to the spec!
+ *
+ * @since JSF 2.0
+ *
+ * @throws IllegalStateException
+ * if the current context already is released!
+ */
@Override
- public Iterator<FacesMessage> getMessages(String clientId)
+ public Map<Object, Object> getAttributes()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
- }
+ assertNotReleased();
+ if (_attributes == null)
+ {
+ _attributes = new HashMap<Object, Object>();
+ }
+ return _attributes;
+ }
+
@Override
- public RenderKit getRenderKit()
+ public boolean isProcessingEvents()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+
+ return _processingEvents;
}
-
+
@Override
- public boolean getRenderResponse()
+ public void setProcessingEvents(boolean processingEvents)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+
+ _processingEvents = processingEvents;
}
+
+ // ~ Methods which are not valid to be called during startup and shutdown, but we implement anyway ------
+
+ // Note that isProjectStage() also is valid to be called, but this method
+ // is already implemented in FacesContext class.
+
+ // ~ Methods which can be called during startup and shutdown, but are not
+ // officially supported by the spec--------------------------------------
+
+
+ // ~ Methods which are unsupported during startup and shutdown-------------
@Override
- public boolean getResponseComplete()
+ public final FacesMessage.Severity getMaximumSeverity()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
-
+
@Override
- public ResponseStream getResponseStream()
+ public List<FacesMessage> getMessageList()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public ResponseWriter getResponseWriter()
+ public List<FacesMessage> getMessageList(String clientId)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void renderResponse()
+ public final Iterator<FacesMessage> getMessages()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
-
+
+
@Override
- public void responseComplete()
+ public final Iterator<String> getClientIdsWithMessages()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setResponseStream(ResponseStream responseStream)
+ public final Iterator<FacesMessage> getMessages(final String clientId)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setResponseWriter(ResponseWriter responseWriter)
+ public final void addMessage(final String clientId, final FacesMessage message)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setViewRoot(UIViewRoot root)
+ public PartialViewContext getPartialViewContext()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
-
+
@Override
- public Map<Object, Object> getAttributes()
+ public boolean isPostback()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
-
+
@Override
- public PhaseId getCurrentPhaseId()
+ public void validationFailed()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public ELContext getELContext()
+ public boolean isValidationFailed()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public ExceptionHandler getExceptionHandler()
+ public final void renderResponse()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public List<FacesMessage> getMessageList()
+ public final void responseComplete()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public List<FacesMessage> getMessageList(String clientId)
+ public PhaseId getCurrentPhaseId()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
-
+
@Override
- public PartialViewContext getPartialViewContext()
+ public void setCurrentPhaseId(PhaseId currentPhaseId)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
-
+
@Override
- public boolean isPostback()
+ public final boolean getRenderResponse()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public boolean isValidationFailed()
+ public final boolean getResponseComplete()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setCurrentPhaseId(PhaseId currentPhaseId)
+ public final void setResponseStream(final ResponseStream responseStream)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setExceptionHandler(ExceptionHandler exceptionHandler)
+ public final ResponseStream getResponseStream()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setProcessingEvents(boolean processingEvents)
+ public final void setResponseWriter(final ResponseWriter responseWriter)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void validationFailed()
+ public final ResponseWriter getResponseWriter()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ assertNotReleased();
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
// ~ private Methods ------------------------------------------------------
@@ -340,5 +479,4 @@ public class StartupFacesContextImpl ext
"Error the FacesContext is already released!");
}
}
-
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/StartupServletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/StartupServletExternalContextImpl.java?rev=957581&r1=957580&r2=957581&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/StartupServletExternalContextImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/StartupServletExternalContextImpl.java Thu Jun 24 15:22:24 2010
@@ -18,8 +18,6 @@
*/
package org.apache.myfaces.context.servlet;
-import static org.apache.myfaces.context.servlet.StartupFacesContextImpl.EXCEPTION_TEXT;
-
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
@@ -29,9 +27,17 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.faces.context.Flash;
import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.myfaces.util.EnumerationIterator;
/**
* An ExternalContext implementation for Servlet environments, which is used
@@ -44,13 +50,14 @@ import javax.servlet.ServletContext;
*/
public class StartupServletExternalContextImpl extends ServletExternalContextImplBase
{
+ public static final String EXCEPTION_TEXT = "This method is not supported during ";
private boolean _startup;
- public StartupServletExternalContextImpl(boolean startup, ServletContext servletContext)
+ public StartupServletExternalContextImpl(final ServletContext servletContext,
+ boolean startup)
{
super(servletContext);
-
_startup = startup;
}
@@ -60,349 +67,358 @@ public class StartupServletExternalConte
// shutdown are implemented in ServletExternalContextImplBase, because they
// are exactly the same as in the real ExternalContext implementation.
+ // ~ Methods which are not valid to be called during startup and shutdown, but we implement anyway ------
+
// ~ Methods which are unsupported during startup and shutdown-------------
@Override
- public void dispatch(String path) throws IOException
- {
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
- }
-
- @Override
public String encodeActionURL(String url)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String encodeNamespace(String name)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String encodeResourceURL(String url)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getAuthType()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getRemoteUser()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Object getRequest()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getRequestContextPath()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Map<String, Object> getRequestCookieMap()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Map<String, String> getRequestHeaderMap()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Map<String, String[]> getRequestHeaderValuesMap()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Locale getRequestLocale()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Iterator<Locale> getRequestLocales()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Map<String, Object> getRequestMap()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Map<String, String> getRequestParameterMap()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Iterator<String> getRequestParameterNames()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Map<String, String[]> getRequestParameterValuesMap()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getRequestPathInfo()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getRequestServletPath()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Object getResponse()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Object getSession(boolean create)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Map<String, Object> getSessionMap()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public Principal getUserPrincipal()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public boolean isUserInRole(String role)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
- }
-
- @Override
- public void redirect(String url) throws IOException
- {
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
- }
-
- @Override
- public void addResponseCookie(String name, String value,
- Map<String, Object> properties)
- {
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
- }
-
- @Override
- public void addResponseHeader(String name, String value)
- {
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String encodeBookmarkableURL(String baseUrl,
Map<String, List<String>> parameters)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String encodePartialActionURL(String url)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String encodeRedirectURL(String baseUrl,
Map<String, List<String>> parameters)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
- }
-
- @Override
- public Flash getFlash()
- {
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getRequestCharacterEncoding()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public int getRequestContentLength()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getRequestContentType()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getRequestScheme()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getRequestServerName()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public int getRequestServerPort()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public int getResponseBufferSize()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getResponseCharacterEncoding()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
public String getResponseContentType()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public OutputStream getResponseOutputStream() throws IOException
+ public void invalidateSession()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public Writer getResponseOutputWriter() throws IOException
+ public boolean isResponseCommitted()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void invalidateSession()
+ public void setRequest(Object request)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public boolean isResponseCommitted()
+ public void setRequestCharacterEncoding(String encoding)
+ throws UnsupportedEncodingException
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void responseFlushBuffer() throws IOException
+ public void setResponse(Object response)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void responseReset()
+ public void setResponseBufferSize(int size)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void responseSendError(int statusCode, String message)
- throws IOException
+ public void setResponseCharacterEncoding(String encoding)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setRequest(Object request)
+ public void setResponseContentLength(int length)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setRequestCharacterEncoding(String encoding)
- throws UnsupportedEncodingException
+ public void setResponseContentType(String contentType)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setResponse(Object response)
+ public void setResponseHeader(String name, String value)
+ {
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
+ }
+
+ @Override
+ public void setResponseStatus(int statusCode)
+ {
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
+ }
+
+ /**
+ * Cannot dispatch because this is not a page request
+ */
+ @Override
+ public void dispatch(String path) throws IOException
{
throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
}
-
+
+ /**
+ * Cannot redirect because this is not a page request
+ */
@Override
- public void setResponseBufferSize(int size)
+ public void redirect(String url) throws IOException
{
throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
}
+
@Override
- public void setResponseCharacterEncoding(String encoding)
+ public void responseFlushBuffer() throws IOException
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setResponseContentLength(int length)
+ public void responseReset()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setResponseContentType(String contentType)
+ public void responseSendError(int statusCode, String message)
+ throws IOException
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
+ }
+
+ @Override
+ public void addResponseCookie(String name, String value,
+ Map<String, Object> properties)
+ {
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setResponseHeader(String name, String value)
+ public void addResponseHeader(String name, String value)
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
@Override
- public void setResponseStatus(int statusCode)
+ public Flash getFlash()
{
- throw new IllegalStateException(EXCEPTION_TEXT + _getTime());
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
}
-
+
+ @Override
+ public OutputStream getResponseOutputStream() throws IOException
+ {
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
+ }
+
+ @Override
+ public Writer getResponseOutputWriter() throws IOException
+ {
+ throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
+ }
+
// ~ private Methods ------------------------------------------------------
/**
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java?rev=957581&r1=957580&r2=957581&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java Thu Jun 24 15:22:24 2010
@@ -29,9 +29,9 @@ import javax.faces.application.Applicati
import javax.faces.application.ApplicationFactory;
import javax.faces.application.ProjectStage;
import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-import javax.faces.context.FacesContextFactory;
import javax.faces.event.PostConstructApplicationEvent;
import javax.faces.event.PreDestroyApplicationEvent;
import javax.faces.lifecycle.Lifecycle;
@@ -47,7 +47,11 @@ import org.apache.myfaces.config.FacesCo
import org.apache.myfaces.config.FacesConfigurator;
import org.apache.myfaces.config.RuntimeConfig;
import org.apache.myfaces.config.annotation.DefaultLifecycleProviderFactory;
+import org.apache.myfaces.context.ReleaseableExternalContext;
import org.apache.myfaces.context.servlet.ServletExternalContextImpl;
+import org.apache.myfaces.context.servlet.StartupFacesContextImpl;
+import org.apache.myfaces.context.servlet.StartupServletExternalContextImpl;
+import org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl;
import org.apache.myfaces.shared_impl.util.StateUtils;
import org.apache.myfaces.shared_impl.webapp.webxml.WebXml;
import org.apache.myfaces.view.facelets.tag.ui.DebugPhaseListener;
@@ -89,8 +93,10 @@ public abstract class AbstractFacesIniti
// by using an ExternalContext. However, that's no problem as long as no
// one tries to call methods depending on either the ServletRequest or
// the ServletResponse.
- ExternalContext externalContext = new ServletExternalContextImpl(
- servletContext, null, null);
+ // JSF 2.0: FacesInitializer now has some new methods to
+ // use proper startup FacesContext and ExternalContext instances.
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ ExternalContext externalContext = facesContext.getExternalContext();
// Parse and validate the web.xml configuration file
WebXml webXml = WebXml.getWebXml(externalContext);
@@ -135,7 +141,7 @@ public abstract class AbstractFacesIniti
DefaultLifecycleProviderFactory.getLifecycleProviderFactory().getLifecycleProvider(externalContext);
// print out a very prominent log message if the project stage is != Production
- if (!FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Production))
+ if (!facesContext.isProjectStage(ProjectStage.Production))
{
ProjectStage projectStage = FacesContext.getCurrentInstance().getApplication().getProjectStage();
StringBuilder message = new StringBuilder("\n\n");
@@ -165,7 +171,7 @@ public abstract class AbstractFacesIniti
log.log(Level.WARNING, message.toString());
// if ProjectStage is Development, install the DebugPhaseListener
- if (FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Development))
+ if (facesContext.isProjectStage(ProjectStage.Development))
{
LifecycleFactory lifeFac = (LifecycleFactory) FactoryFinder
.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
@@ -173,8 +179,6 @@ public abstract class AbstractFacesIniti
lifecycle.addPhaseListener(new DebugPhaseListener());
}
}
-
- releaseFacesContext();
} catch (Exception ex) {
log.log(Level.SEVERE, "An error occured while initializing MyFaces: "
@@ -200,25 +204,9 @@ public abstract class AbstractFacesIniti
*/
private void dispatchInitDestroyEvent(ServletContext servletContext, Class eventClass) {
ApplicationFactory appFac = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
- FacesContext fc = null;
-
- fc = FacesContext.getCurrentInstance();
- if (fc == null) {
- LifecycleFactory lifeFac = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
- FacesContextFactory facFac = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
- fc = facFac.getFacesContext(servletContext,
- new _SystemEventServletRequest(),
- new _SystemEventServletResponse(),
- lifeFac.getLifecycle(getLifecycleId(servletContext)));
- }
-
- // in order to allow FacesContext.getViewRoot calls during startup/shutdown listeners,
- // we need to initialize a new ViewRoot with locale set to Locale.getDefault().
- UIViewRoot root = new UIViewRoot();
- root.setLocale(Locale.getDefault());
- fc.setViewRoot(root);
- appFac.getApplication().publishEvent(fc, eventClass, Application.class, appFac.getApplication());
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ appFac.getApplication().publishEvent(facesContext, eventClass, Application.class, appFac.getApplication());
}
/**
@@ -243,7 +231,6 @@ public abstract class AbstractFacesIniti
*/
public void destroyFaces(ServletContext servletContext) {
dispatchInitDestroyEvent(servletContext, PreDestroyApplicationEvent.class);
- releaseFacesContext();
// TODO is it possible to make a real cleanup?
}
@@ -343,7 +330,45 @@ public abstract class AbstractFacesIniti
return null;
}
-
+
+ public FacesContext initStartupFacesContext(ServletContext servletContext)
+ {
+ // We cannot use FacesContextFactory, because it is necessary to initialize before Application and RenderKit factories.
+ // so we should use different object.
+ ExternalContext externalContext = new StartupServletExternalContextImpl(servletContext, true);
+ ExceptionHandler exceptionHandler = new ExceptionHandlerImpl();
+ FacesContext facesContext = new StartupFacesContextImpl(externalContext, (ReleaseableExternalContext) externalContext, exceptionHandler, true);
+ // in order to allow FacesContext.getViewRoot calls during startup/shutdown listeners,
+ // we need to initialize a new ViewRoot with locale set to Locale.getDefault().
+ UIViewRoot root = new UIViewRoot();
+ root.setLocale(Locale.getDefault());
+ facesContext.setViewRoot(root);
+ return facesContext;
+ }
+
+ public void destroyStartupFacesContext(FacesContext facesContext)
+ {
+ releaseFacesContext();
+ }
+
+ public FacesContext initShutdownFacesContext(ServletContext servletContext)
+ {
+ ExternalContext externalContext = new StartupServletExternalContextImpl(servletContext, false);
+ ExceptionHandler exceptionHandler = new ExceptionHandlerImpl();
+ FacesContext facesContext = new StartupFacesContextImpl(externalContext, (ReleaseableExternalContext) externalContext, exceptionHandler, true);
+ // in order to allow FacesContext.getViewRoot calls during startup/shutdown listeners,
+ // we need to initialize a new ViewRoot with locale set to Locale.getDefault().
+ UIViewRoot root = new UIViewRoot();
+ root.setLocale(Locale.getDefault());
+ facesContext.setViewRoot(root);
+ return facesContext;
+ }
+
+ public void destroyShutdownFacesContext(FacesContext facesContext)
+ {
+ releaseFacesContext();
+ }
+
/**
* Performs initialization tasks depending on the current environment.
*
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java?rev=957581&r1=957580&r2=957581&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java Thu Jun 24 15:22:24 2010
@@ -18,6 +18,7 @@
*/
package org.apache.myfaces.webapp;
+import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
/**
@@ -29,4 +30,28 @@ public interface FacesInitializer
void initFaces(ServletContext servletContext);
void destroyFaces(ServletContext servletContext);
+
+ /**
+ * @since 2.0.1
+ * @param facesContext
+ */
+ FacesContext initStartupFacesContext(ServletContext servletContext);
+
+ /**
+ * @since 2.0.1
+ * @param facesContext
+ */
+ void destroyStartupFacesContext(FacesContext facesContext);
+
+ /**
+ * @since 2.0.1
+ * @param facesContext
+ */
+ FacesContext initShutdownFacesContext(ServletContext servletContext);
+
+ /**
+ * @since 2.0.1
+ * @param facesContext
+ */
+ void destroyShutdownFacesContext(FacesContext facesContext);
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/MyFacesServlet.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/MyFacesServlet.java?rev=957581&r1=957580&r2=957581&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/MyFacesServlet.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/MyFacesServlet.java Thu Jun 24 15:22:24 2010
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.faces.context.FacesContext;
import javax.faces.webapp.FacesServlet;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
@@ -92,15 +93,48 @@ public class MyFacesServlet implements S
//Check, if ServletContextListener already called
ServletContext servletContext = servletConfig.getServletContext();
Boolean b = (Boolean)servletContext.getAttribute(StartupServletContextListener.FACES_INIT_DONE);
+
+ //Create startup FacesContext before initialize
+ FacesContext facesContext = initStartupFacesContext(servletContext);
+
if (b == null || b.booleanValue() == false)
{
if(log.isLoggable(Level.WARNING))
log.warning("ServletContextListener not yet called");
initFaces(servletConfig.getServletContext());
}
+
+ //Destroy startup FacesContext
+ destroyStartupFacesContext(facesContext);
+
delegate.init(servletConfig);
log.info("MyFacesServlet for context '" + servletConfig.getServletContext().getRealPath("/") + "' initialized.");
}
+
+ protected FacesContext initStartupFacesContext(ServletContext context)
+ {
+ if (_facesInitializer == null)
+ {
+ if (ContainerUtils.isJsp21(context))
+ {
+ _facesInitializer = new Jsp21FacesInitializer();
+ }
+ else
+ {
+ _facesInitializer = new Jsp20FacesInitializer();
+ }
+ }
+
+ return _facesInitializer.initStartupFacesContext(context);
+ }
+
+ protected void destroyStartupFacesContext(FacesContext facesContext)
+ {
+ if (_facesInitializer != null)
+ {
+ _facesInitializer.destroyStartupFacesContext(facesContext);
+ }
+ }
public void service(ServletRequest request, ServletResponse response)
throws IOException,
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=957581&r1=957580&r2=957581&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 Thu Jun 24 15:22:24 2010
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.FactoryFinder;
+import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
@@ -63,7 +64,7 @@ public class StartupServletContextListen
ServletRequestListener, ServletRequestAttributeListener,
ServletContextAttributeListener
{
- static final String FACES_INIT_DONE = StartupServletContextListener.class.getName() + ".FACES_INIT_DONE";
+ static final String FACES_INIT_DONE = "org.apache.myfaces.webapp.StartupServletContextListener.FACES_INIT_DONE";
/**
* comma delimited list of plugin classes which can be hooked into myfaces
@@ -153,6 +154,9 @@ public class StartupServletContextListen
_servletContext = event.getServletContext();
Boolean b = (Boolean) _servletContext.getAttribute(FACES_INIT_DONE);
+ //Create startup FacesContext before initialize
+ FacesContext facesContext = initStartupFacesContext(_servletContext);
+
if (b == null || b.booleanValue() == false)
{
dispatchInitializationEvent(event, FACES_INIT_PHASE_PREINIT);
@@ -167,6 +171,9 @@ public class StartupServletContextListen
// call contextInitialized on ManagedBeanDestroyerListener
_detroyerListener.contextInitialized(event);
+
+ //Destroy startup FacesContext
+ destroyStartupFacesContext(facesContext);
}
protected void initFaces(ServletContext context)
@@ -185,6 +192,56 @@ public class StartupServletContextListen
_facesInitializer.initFaces(_servletContext);
}
+
+ protected FacesContext initStartupFacesContext(ServletContext context)
+ {
+ if (_facesInitializer == null)
+ {
+ if (ContainerUtils.isJsp21(context))
+ {
+ _facesInitializer = new Jsp21FacesInitializer();
+ }
+ else
+ {
+ _facesInitializer = new Jsp20FacesInitializer();
+ }
+ }
+
+ return _facesInitializer.initStartupFacesContext(context);
+ }
+
+ protected void destroyStartupFacesContext(FacesContext facesContext)
+ {
+ if (_facesInitializer != null && _servletContext != null)
+ {
+ _facesInitializer.destroyStartupFacesContext(facesContext);
+ }
+ }
+
+ protected FacesContext initShutdownFacesContext(ServletContext context)
+ {
+ if (_facesInitializer == null)
+ {
+ if (ContainerUtils.isJsp21(context))
+ {
+ _facesInitializer = new Jsp21FacesInitializer();
+ }
+ else
+ {
+ _facesInitializer = new Jsp20FacesInitializer();
+ }
+ }
+
+ return _facesInitializer.initShutdownFacesContext(context);
+ }
+
+ protected void destroyShutdownFacesContext(FacesContext facesContext)
+ {
+ if (_facesInitializer != null && _servletContext != null)
+ {
+ _facesInitializer.destroyShutdownFacesContext(facesContext);
+ }
+ }
/**
* configure the faces initializer
@@ -206,6 +263,12 @@ public class StartupServletContextListen
public void contextDestroyed(ServletContextEvent event)
{
+ //Create startup FacesContext before start undeploy
+ FacesContext facesContext = null;
+ if (_facesInitializer != null && _servletContext != null)
+ {
+ facesContext = initShutdownFacesContext(_servletContext);
+ }
dispatchInitializationEvent(event, FACES_INIT_PHASE_PREDESTROY);
// call contextDestroyed on ManagedBeanDestroyerListener to destroy the attributes
_detroyerListener.contextDestroyed(event);
@@ -214,6 +277,13 @@ public class StartupServletContextListen
{
_facesInitializer.destroyFaces(_servletContext);
}
+
+ // Destroy startup FacesContext, but note we do before publish postdestroy event on
+ // plugins and before release factories.
+ if (facesContext != null)
+ {
+ destroyShutdownFacesContext(facesContext);
+ }
FactoryFinder.releaseFactories();
dispatchInitializationEvent(event, FACES_INIT_PHASE_POSTDESTROY);