Posts Tagged ‘EL’

For the use of JSF you only need a servlet container (no full application server).

JSF 1.2, 2.0: Servlet 2.5 / JSP 2.1 container

JSF 1.2 and JSF 2.0 depend only on Servlet 2.5 / JSP 2.1 containers. Note that EL 2.1 is a component of the JSP 2.1 Specification. This is the case in JEE 5 AppServers:

  • Tomcat 6
  • Glassfish 2
  • JBoss AS 5
  • Oracle WebLogic 11g
  • IBM WebSphere 7, etc.

E.g. So you can use JSF 2.0 in Tomcat 6, but not the features of EL 2.2, like call JSF action method with arguments. To tune Tomcat 6 towards Java EE 6 see here.

JSF 2.1, 2.2: Servlet 3.0 / JSP 2.2 container

JSF 2.1 and JSF 2.2 depend on Servlet 3.0 / JSP 2.2 containers. Note that EL 2.2 is a component of the JSP 2.2 Specification. This is the case in JEE 6 AppServers:

  • Tomcat 7
  • Glassfish 3
  • JBoss AS 6
  • Oracle WebLogic 12g
  • IBM WebSphere 8
  • or newer versions

For an overview of JEE 6 compatible servers:
What’s new in JSF 2.1? It’s mainly a maintenance release: (German)

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


Unfortunately, there are no functions in EL concerning Strings. This may be of interest when you want to display different data than delivered from a backing bean, and provide the logic in the logic in the view (pro: can be easily modified, con: logic in the view?). There are several ways (client-side with JavaScript/server-side with Java), but I want to show how to use (already existing) JSTL functions inside EL Expression without writing any extra Java nor JavaScript code:

  • Add JSTL functions namespace in Facelets XHTML:


  • JSTL function startsWith inside EL expression


  • JSF Example: filtering values starting with a prefix:

<h:outputText value="#{fn:startsWith(beanName.fieldName,'PREFIX_')} ? '' : beanName.fieldName "/>

The other JSTL functions are, see JSTL Functions API documentation:

  • toUpperCase, toLowerCase: Changes the capitalization of a string
  • substring, substringBefore, substringAfter: Gets a subset of a string
  • trim: Trims white space from a string
  • replace: Replaces characters in a string
  • indexOf, startsWith, endsWith, contains, containsIgnoreCase: Checks whether a string contains another string
  • split: Splits a string into an array
  •  join: Joins a collection into a string
  • escapeXml: Escapes XML characters in a string
  • length: Returns the number of items in a collection, or the number of characters in a string

, , ,


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 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:,
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 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 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 For Hibernate just get the zip from and follow the good documentation.

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

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