JSF 2.3 don't work over Tomcat 8

4k Views Asked by At

I'm trying to test the new features of JSF 2.3 on Tomcat 8, but nothing works.
A JSF 2.2 compatible code works fine with this configuration, but as for a new JSF 2.3 feature it fails.
For example, the following code causes the following failure to start the application.

WELD-001408: Unsatisfied dependencies for type FacesContext with qualifiers @Default

My configuration files are as follows.

POM.xml file https://pastebin.com/84MEw2aS

<dependencies>
    <!-- CDI ..........................................-->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.2</version>
    </dependency>

    <!--JBoss/Weld Refrence Implementation for CDI on a Servlet Container -->    
    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet</artifactId>
        <version>2.4.3.Final</version>
    </dependency>

    <!-- JSF ..........................................-->
    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>javax.faces-api</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>2.3.0</version>
    </dependency>

    <dependency>
        <groupId>org.omnifaces</groupId>
        <artifactId>omnifaces</artifactId>
        <version>2.6.2</version>
    </dependency>  

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/JSF23"> 
    <Resource auth="Container"
              factory="org.jboss.weld.resources.ManagerObjectFactory"
              name="BeanManager"
              type="javax.enterprise.inject.spi.BeanManager"/>
</Context>


beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       version="1.2"
       bean-discovery-mode="all">
</beans>

web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.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">
    <display-name>JSF 2.3</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>    
    <listener>
        <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
    </listener>
    <resource-env-ref>        
        <resource-env-ref-name>BeanManager</resource-env-ref-name>
        <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
    </resource-env-ref>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
</web-app>


Versions

  • Apache Tomcat 8.0.27 or Apache Tomcat 8.5.14
  • JDK 8.
  • NetBeans8.2
  • JSF 2.3
  • Weld 2.4.3
  • Omnifaces 2.6.2

The Tomcat log is as follows

log Tomcat https://pastebin.com/fufUfQtj

The following code causes the error

package es.prueba.jsf23;

import javax.enterprise.context.ApplicationScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

@ApplicationScoped
public class ApplicationBean {

    @Inject
    private FacesContext facesContext;

    public FacesContext getFacesContext() {
        return facesContext;
    }

    public void setFacesContext(FacesContext facesContext) {
        this.facesContext = facesContext;
    }    
}

What am I doing wrong?

2

There are 2 best solutions below

0
On

Use the new Glashfish application server. It's called Payara Server. It's awesome.

1
On

You need to activate JSF 2.3, by default it runs with JSF 2.2 compatibility.

Add a class like this:

@FacesConfig(version = Version.JSF_2_3)
@ApplicationScoped
public class JSF23Activator {
}

Another tips:

  • Check that you have a 'faces-config.xml' file in WEB-INF folder (with a 2.3 schema)
  • Check that you have a 'beans.xml' file in WEB-INF folder (with a 'bean-discovery-mode="all"' property)

You will have more details following this link about the Activator.