1

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?

Gallegote
  • 43
  • 1
  • 7
  • The dependency validation-api jar from javax seems to be missing as pointed out from the stack trace. You will have to add it as dependency. – OTM May 12 '17 at 04:21
  • I believe that the validation-api jar is not necessary in this case. Anyway, I have tried to add this api and it gives me the same error. – Gallegote May 12 '17 at 07:09
  • It Looks like new features of CDI has been introduced in jsf2.3 which is different from the earlier versions. The facescontext Injection does not seem to have any qualifiers in jsf 2.3 like ` @Default or @Any`. You may have to remove the qualifiers. Please see http://arjan-tijms.omnifaces.org/p/jsf-23.html#1417 – OTM May 12 '17 at 17:09
  • I do not understand what qualifiers I have to remove. My code is the same as the one shown by Arjan Tijms in the following link http://arjan-tijms.omnifaces.org/p/jsf-23.html#1412 – Gallegote May 12 '17 at 17:49
  • It looks from the stacktrace, that you have "@Inject @Any" private beans.PhonePrefixServiceBean.facesContext". If it is so then " @Any " is a qualifier. – OTM May 12 '17 at 18:14
  • I have the same issue did you managed to find a solution? – Peter Penzov May 27 '17 at 15:31
  • i am also facing the same problem, any idea to integrate facescontext 2.3 in viewscoped bean? – umaair_653 Aug 17 '17 at 08:25

2 Answers2

0

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.

Ariel Carrera
  • 5,113
  • 25
  • 36
-6

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

JediSal
  • 65
  • 4