This should work theoretically with every Servlet 2.5 / JSP 2.1 container, but tested with Tomcat 6 only…


If your customer forces you to run your WebApps in an old Servlet 2.5 / JSP 2.1 container ;-) , but you want to kick off using new JEE 6 stuff, then heres how you get started:

JSF 2.0

JSF 2.0 just needs Servlet 2.5 / JSP 2.1 container (JSF 2.1+ needs alredy Servlet 3.0). Download the reference implementation Mojarra or Apache MyFaces and put the two jars into the WEB-INF/lib:


EL 2.2 or JBoss EL

Have you ever wished to pass an argument to your JSF-actions in your view? Like

<h:commandButton value="edit" action="#{bean.edit(user)}" />

with backing bean method

public void edit(User user) {...}

JBoss EL 2.0.1.GA

This is possible with JBoss EL implementation, see http://docs.jboss.org/seam/2.0.1.GA/reference/en/html/elenhancements.html. Add to your pom:


and to your web.xml


EL 2.2

Or use EL 2.2, which is a component of the JSP 2.2 spec. You need to put the two EL JARs into the WEB-INF/lib: el-api-2.2.0.jar, el-impl-2.2.0.jar. Add to your web.xml:


Note: If you also use CDI with Weld, this ends up in an exception:
LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;"
One way out is to replace in the apache-tomcat/lib the el-api.jar with el-api-2.2.jar and el-impl-2.2.jar and put in your pom.xml:


If you cannot change the server itself then stick to JBoss EL.


If you want to use CDI managed beans (@Named) instead of JSF managed beans (@ManagedBean) in a plain Servlet container, then you can use the reference implementation Weld: http://seamframework.org/Weld,
CDI is the new JEE 6-standardized way for managing beans: it’s more robust, and the same as in an EJB context. Furthermore you can use a conversation scope. I still like the JSF view scope, so maybe drop JSF management totally, or mix it.
For setup refer to http://docs.jboss.org/weld/reference/1.0.0/en-US/html/environments.html. There it is explained:

Just drop into WEB-INF/lib


and add to your web.xml:

  <description>Object factory for the CDI Bean Manager</description>

Bean Validation

“Declare once, validate anywhere!” is the advertisement for Bean validation: Don’t put your validation in the views, DAOs/DTOs, etc., but put your validation only at one place:
your beans (although in real life in the database remain ranges, constraints, etc., so some redundancy remains…). If you have different pages with input data to the same data, then this is a big advantage for maintenance: change at one place.

public class Bean {
private String name;

Again use the RI from Hibernate https://validator.hibernate.org/ and drop it to WEB-INF/lib:

all JARs in the lib directory of the downloaded zip file.

Note: JSF 2.0 directly supports Bean Validation. In JSF 1.2 you could use RichFaces 3.3.3.

JPA 2.0

Some drawbacks without a real AppServer is that

  • manage your transactions by yourself with EntityTransaction (no JTA transactions).
  • direct resource handling, i.e. use the persistence factory EntityManagerFactory to obtain an EnitityManager (no injections possible, because of the lack of EJBs), also don’t forget to close your EntityManager…

Get a JPA provider, e.g. Hibernate and EclipseLink. For EclipseLink, see http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial. For Hibernate just get the zip from http://www.hibernate.org/ and follow the good documentation.

You need to setup your persistence.xml and make some provider and database specific configurations.

, , , , , , , , , , , , , ,

One Response to “Tomcat 6 and JEE 6? Upgrading to JSF 2.0, EL 2.2, CDI, JPA and Bean Validation”

Add reply