Reputation: 729
I created a Maven Web Application using JSF 2.2 , Primefaces, Tomcat 7 dependencies.
My JSF's implemention is Mojarra 2.2.4, I added this dependecies on my POM:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency>
But unfortunately, I have problem with tomcat7-maven-plugin
and its embedded tomcat. If I use tomcat7:run
command, my webapp starts without problem, but when it try to load managed bean I receive this error:
Target Unreachable, identifier 'testBean' resolved to null
This is a sign that the webapp is using JSF 1.x
instead of JSF 2.x
. The configurator of JSF 1.x
does not recognize @ManagedBean
annotations which will cause that they're not loaded/initialized automagically without the need for faces-config.xml.
I'm using tomcat embedded 7.0.50, configured using it: http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/adjust-embedded-tomcat-version.html
But despite I doesn't recognize @ManagedBean
annotaions, it works only using managedbean tag on faces-config.xml
.
Is there a way to include JSF 2.x
support to Tomcat Embedded for maven7-tomcat-plugin
?
PS: tomcat7:run-war
works, but I don't like because obviously it a static run, without any possibility to change xhtml code (e.g.) on fly.
Upvotes: 4
Views: 3053
Reputation: 729
I resolved switched from Mojarra 2.2.4 to MyFaces 2.2.0 following these steps:
add MyFaces dependecies in my POM:
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>2.2.0</version>
<scope>compile</scope>
</dependency>
change listener-class on my web.xml
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
add context-param on my web.xml
<context-param>
<description>Defines which packages to scan for beans, separated by commas.
Useful for when using maven and jetty:run (version 6) or tomcat:run
</description>
<param-name>org.apache.myfaces.annotation.SCAN_PACKAGES</param-name>
<param-value>eu.dedalus</param-value>
.5 remove jsf-api e jsf-impl from WEB-INF/lib.
.6 [ECLIPSE ONLY]
add myfaces.api and myfaces-impl libraries in Build Path using M2REPO variable and remove jsf-api and jsf-impl libraries.
Thanks to https://stackoverflow.com/users/814956/lu4242!
Upvotes: 3