jsf-2myfacesfacesservletweb-fragment

FacesServlet not working in web fragment


I have two web applications (web-module1.war & web-module2.war) and I want to use a web fragment (web-core.jar) for common servlet declaration like FacesServlet.

When I declare FacesServlet in web.xml no problem, but when I move this declaration to web-fragment.xml I get this error :

java.lang.IllegalStateException: No Factories configured for this Application. 
This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions!
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>

I don't have this problem with other servlet/filter declaration !

The web-fragment.xml is in web-core.jar's META-INF folder as well as the faces-config.xml.

The web-core.jar is declared as a maven dependency (I can find it in the WEB-INF/lib).

This is web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" metadata-complete="false"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <absolute-ordering>
        <name>core_web_fragment</name>
    </absolute-ordering>

</web-app>

And web-fragment.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-fragment metadata-complete="true" version="3.0"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">

    <name>core_web_fragment</name>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-*.xml</param-value>
    </context-param>
    <!-- /Spring Config -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
        <param-value>true</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>inscription.xhtml</welcome-file>
    </welcome-file-list>
</web-fragment>

I'm using Tomcat7


Solution

  • If you are using Apache Myfaces JSF implementation this is a known bug

    So u should change it ( use MOJARRA for example)