wtlucy closed pull request #17: MYFACES-3629 add context attr for case when
faces servlet is found by SCI - 2.2.x
URL: https://github.com/apache/myfaces/pull/17
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/impl/src/main/java/org/apache/myfaces/ee6/MyFacesContainerInitializer.java
b/impl/src/main/java/org/apache/myfaces/ee6/MyFacesContainerInitializer.java
index de74039da..2ebd151eb 100644
--- a/impl/src/main/java/org/apache/myfaces/ee6/MyFacesContainerInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/ee6/MyFacesContainerInitializer.java
@@ -113,6 +113,13 @@
*/
private static final String FACES_SERVLET_ADDED_ATTRIBUTE =
"org.apache.myfaces.DYNAMICALLY_ADDED_FACES_SERVLET";
+ /**
+ * If the servlet mapping for the FacesServlet is found on the
ServletContext, Boolean.TRUE
+ * is stored under this key in the ServletContext.
+ * ATTENTION: this constant is duplicate in AbstractFacesInitializer.
+ */
+ private static final String FACES_SERVLET_FOUND =
"org.apache.myfaces.FACES_SERVLET_FOUND";
+
private static final String INITIALIZE_ALWAYS_STANDALONE =
"org.apache.myfaces.INITIALIZE_ALWAYS_STANDALONE";
/**
@@ -162,7 +169,8 @@ public void onStartup(Set<Class<?>> clazzes, ServletContext
servletContext) thro
if (FACES_SERVLET_CLASS.getName().equals(className)
|| isDelegatedFacesServlet(className))
{
- // we found a FacesServlet, so we have nothing to do!
+ // we found a FacesServlet; set an attribute for use
during initialization
+ servletContext.setAttribute(FACES_SERVLET_FOUND,
Boolean.TRUE);
return;
}
}
diff --git
a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
index 3a833f719..c10bef7f5 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
@@ -83,6 +83,13 @@
*/
private static final String FACES_SERVLET_ADDED_ATTRIBUTE =
"org.apache.myfaces.DYNAMICALLY_ADDED_FACES_SERVLET";
+ /**
+ * If the servlet mapping for the FacesServlet is found on the
ServletContext, Boolean.TRUE
+ * is stored under this key in the ServletContext.
+ * ATTENTION: this constant is duplicate in MyFacesContainerInitializer.
+ */
+ private static final String FACES_SERVLET_FOUND =
"org.apache.myfaces.FACES_SERVLET_FOUND";
+
/**
* This parameter specifies the ExpressionFactory implementation to use.
*/
@@ -153,16 +160,23 @@ public void initFaces(ServletContext servletContext)
if
(webConfigProvider.getFacesServletMappings(facesContext.getExternalContext()).isEmpty())
{
- // check if the FacesServlet has been added dynamically
- // in a Servlet 3.0 environment by
MyFacesContainerInitializer
- Boolean mappingAdded = (Boolean)
servletContext.getAttribute(FACES_SERVLET_ADDED_ATTRIBUTE);
+ // check to see if the FacesServlet was found by
MyFacesContainerInitializer
+ Boolean mappingAdded = (Boolean)
servletContext.getAttribute(FACES_SERVLET_FOUND);
+
if (mappingAdded == null || !mappingAdded)
{
- if (log.isLoggable(Level.WARNING))
+ // check if the FacesServlet has been added dynamically
+ // in a Servlet 3.0 environment by
MyFacesContainerInitializer
+ mappingAdded = (Boolean)
servletContext.getAttribute(FACES_SERVLET_ADDED_ATTRIBUTE);
+
+ if (mappingAdded == null || !mappingAdded)
{
- log.warning("No mappings of FacesServlet found.
Abort initializing MyFaces.");
+ if (log.isLoggable(Level.WARNING))
+ {
+ log.warning("No mappings of FacesServlet
found. Abort initializing MyFaces.");
+ }
+ return;
}
- return;
}
}
}
@@ -347,16 +361,23 @@ public void destroyFaces(ServletContext servletContext)
if
(webConfigProvider.getFacesServletMappings(facesContext.getExternalContext()).isEmpty())
{
- // check if the FacesServlet has been added dynamically
- // in a Servlet 3.0 environment by MyFacesContainerInitializer
- Boolean mappingAdded = (Boolean)
servletContext.getAttribute(FACES_SERVLET_ADDED_ATTRIBUTE);
+ // check to see if the FacesServlet was found by
MyFacesContainerInitializer
+ Boolean mappingAdded = (Boolean)
servletContext.getAttribute(FACES_SERVLET_FOUND);
+
if (mappingAdded == null || !mappingAdded)
{
- if (log.isLoggable(Level.WARNING))
+ // check if the FacesServlet has been added dynamically
+ // in a Servlet 3.0 environment by
MyFacesContainerInitializer
+ mappingAdded = (Boolean)
servletContext.getAttribute(FACES_SERVLET_ADDED_ATTRIBUTE);
+
+ if (mappingAdded == null || !mappingAdded)
{
- log.warning("No mappings of FacesServlet found. Abort
destroy MyFaces.");
+ if (log.isLoggable(Level.WARNING))
+ {
+ log.warning("No mappings of FacesServlet found.
Abort destroy MyFaces.");
+ }
+ return;
}
- return;
}
}
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services