[ 
https://issues.apache.org/jira/browse/MYFACES-3629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16590697#comment-16590697
 ] 

ASF GitHub Bot commented on MYFACES-3629:
-----------------------------------------

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:
us...@infra.apache.org


> StartupServletContextListener crashes if FacesServlet is defined in 
> web-fragments.
> ----------------------------------------------------------------------------------
>
>                 Key: MYFACES-3629
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3629
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: JSR-314
>    Affects Versions: 2.1.9
>            Reporter: Mark Struberg
>            Assignee: Bill Lucy
>            Priority: Major
>             Fix For: 2.2.13, 2.3.2
>
>
> I'm trying to move all my common web.xml content from my 12 webapps in an EAR 
> into a web-fragment.xml which gets referenced.
> MyFaces fails with the following Exception if the FacesServlet is defined in 
> a web-fragment rather than web.xml:
> >If you did that and find nothing, the mistake might be due to the fact that 
> >you use some special  
> >web-containers which do not support registering context-listeners via TLD 
> >files and a context listener is not 
> > setup in your web.xml.
> > A typical config looks like this;
> > <listener>
> >  
> > <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
> > </listener>
> In general the StartupServletContextListener defined in JSF-2.1 is pure PITA 
> as it does crash apps which do not have any JSF content at all!.
> We should scan if we either find a faces-config.xml or any *.xhtml files in 
> the app and if not we shall not start JSF.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to