Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application error with MyFaces 1.2: java.lang.IllegalStateException: No Factories configured for this Application

For my app I'm using Tomcat 6.0.x and Mojarra 1.2_04 JSF implementation. It works fine, just I would like to switch now to MyFaces 1.2_10 impl of JSF.

During the deployment of my app a get the following error:

ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myApp]] StandardWrapper.Throwable
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>

    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:106)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:137)
    at org.apache.myfaces.webapp.MyFacesServlet.init(MyFacesServlet.java:113)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
...

Here is part of my web.xml configuration:

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <!-- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> -->
        <servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    ...
    <listener>
         <listener- class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    </listener>

Has anyone experienced similar error, and what should I do i order to fix it? Thanx!

EDIT:

I was able to fix the problem. Since I am using delegator for FacesServlet, it turned out that this delegator was causing the problem. All I needed to do is to make this class implement DelegatedFacesServlet, and I've removed org.apache.myfaces.webapp.StartupServletContextListener. Here is my web.xml now:

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <!-- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> -->
        <servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Faces Servlet Delegator</servlet-name>
        <servlet-class>com.myapp.web.FacesServletDelegator</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet Delegator</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

and here is FacesServletDelegator

public class PLMFacesServlet extends HttpServlet implements DelegatedFacesServlet {

    private MyFacesServlet delegate;

    public final void init(ServletConfig servletConfig) throws ServletException {
        delegate = new MyFacesServlet();
        delegate.init(servletConfig);
    }

    public final void destroy() {
        delegate.destroy();
    }

    public final ServletConfig getServletConfig() {
        return delegate.getServletConfig();
    }

    public final String getServletInfo() {
        return delegate.getServletInfo();
    }

    public final void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {

       try {
           delegate.service(request, response);
       } catch(Exception e) {}
    }
    // some other code...
}

EDIT 2:

Following BalusC advice, I've edited my web.xml a bit, here is the final version:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Faces Servlet Delegator</servlet-name>
    <servlet-class>com.myapp.web.FacesServletDelegator</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet Delegator</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
like image 386
Igor Avatar asked Jun 22 '11 08:06

Igor


1 Answers

In my case, the removal of the following line from my web.xml:

<load-on-startup>1</load-on-startup>

...was what made the error disappear.

(Was fixing up a pure Tomcat 7 to work with JSF.)

like image 105
Andrzej Szydermann Avatar answered Oct 19 '22 23:10

Andrzej Szydermann