JSF2: How to add the magic of EL (EL2) to JSF
LincolnEver wonder why you can’t pass parameters to EL method-expressions? Well, now you can, and it’s easy to incorporate!
This quick guide assumes you are using Maven. And is a followup to the post: h:dataTable vs ui:repeat – how to get the selected row.
Get the EL dependencies through maven
You can get EL2 here, just include the desired repository and implementation:
<repository> <id>sun</id> <url>http://download.java.net/maven/2/</url> </repository> <dependency> <groupId>javax.el</groupId> <artifactId>el-api</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>org.glassfish.web</groupId> <artifactId>el-impl</artifactId> <version>2.2</version> </dependency>
Configuring Faces to use the new ExpressionFactory
Then register EL in web.xml
<context-param> <param-name>com.sun.faces.expressionFactory</param-name> <param-value>com.sun.el.ExpressionFactoryImpl</param-value> </context-param>
That’s it! You should now be able to pass parameters like a pro.
<h:commandButton value="Save" action="#{taskController.saveTaskAjax(cc.attrs.story, cc.attrs.task)}"> <f:ajax execute="taskBlock" render="taskBlock" /> </h:commandButton> <!-- or --> <h:commandLink id="removeTask" title="remove" styleClass="m5t" rendered="#{cc.attrs.deletable}" immediate="true" onclick="return confirm('Really delete this task?');" action="#{taskController.removeTask(cc.attrs.story, cc.attrs.task)}"> <f:ajax execute="@this" render="@form" /> [remove] </h:commandLink>
![]() | About the author:Lincoln Baxter, III is a Senior Software Engineer at Red Hat, Inc., working on JBoss open-source projects. This blog represents his personal thoughts and perspectives, not necessarily those of his employer. He is a founder of OcpSoft, the author of PrettyFaces: bookmarking, SEO extensions for JSF, and an individual member of the JavaServer™ Faces Expert Group. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals. His latest project is ScrumShark, an open-source, agile project management tool. |
Posted in JSF2


[...] instructions on how to: include EL2 in a JSF project go [...]
Technically JBoss EL 2.1 is not the same as EL 2 (which isn’t EL 2 at all, but rather the EL being delivered in MR2 of the JSR-245: JSP 2.1 specification). I know, it’s really confusing.
You should see if you can use the actual EL implementation from the Java EE 6 reference implementation (GlassFish V3).
That sound cool, but what about JSF 1.2? can we use EL 2.0 with JSF 1.2 ???
Any idea….
I don’t know the answer to that one. Try it out
[...] Check it out. Good read! [...]
You can add JSF 2.0 and Unified EL (EL 2) magic to Glassfish V2.1.1 in 2 ways.
1) If you want to completly replace JSF 1.x with 2.x in your glassfish V2.1.1 installation
a) Remove existing jsf-impl.jar in ${com.sun.aas.installRoot}/lib
b) Add following JSF2 and unified EL jars. i.e. jsf-api-2.1.jar, jsf-impl-2.1.jar,el-api-2.1.jar, el-impl-2.1.jar in in ${com.sun.aas.installRoot}/lib.
c) Add or update classpath-prefix=”${com.sun.aas.installRoot}/lib/jsf-api.jar;${com.sun.aas.installRoot}/lib/jsf-imp.jar;${com.sun.aas.installRoot}/lib/el-api.jar;${com.sun.aas.installRoot}/lib/el-impl.jar” in ${com.sun.aas.installRoot}/domains//config/domain.xml under as an attribute.
2) If you want to keep JSF 1.x as the default implementation on your glassfish instance but want to implement JSF 2.x only on one of your applications
a) Add el-api-2.1.jar, el-impl-2.1.jar in ${com.sun.aas.installRoot}/lib.
b) Include jsf-api-2.1.jar, jsf-impl-2.1.jar in lib directory of your application war.
c) Add add sun-web.xml under /WEB-INF/ directory of your application war with following properties
mojarra2
d) Add or update classpath-prefix=”${com.sun.aas.installRoot}/lib/el-api.jar;${com.sun.aas.installRoot}/lib/el-impl.jar” in ${com.sun.aas.installRoot}/domains//config/domain.xml under as an attribute.
Hope this helps. Enjoy!!!
Note: (This does not work in Glassfish V2.0 or V2.1)
classpath-prefix=”${com.sun.aas.installRoot}/lib/el-api.jar;${com.sun.aas.installRoot}/lib/el-impl.jar” in ${com.sun.aas.installRoot}/domains/your domain name/config/domain.xml under as an attribute.