"Simple Software"

OcpSoft

JSF2: How to add the magic of EL (EL2) to JSF

September 14th, 2009 by Lincoln

Ever 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>


Post to Twitter Post to Delicious Post to Digg Post to StumbleUpon

Posted in JSF2

7 Comments

  1. Dan Allen says:

    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).

  2. That sound cool, but what about JSF 1.2? can we use EL 2.0 with JSF 1.2 ???

    Any idea….

  3. Lincoln says:

    I don’t know the answer to that one. Try it out :)

  4. Jay says:

    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)

    1. Jay says:

      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.

Leave a Comment




Please note: In order to submit code or special characters, wrap it in <pre lang="java"> </pre> - or your tags will be eaten.

Please note: Comment moderation is enabled and may delay your comment from appearing. There is no need to resubmit your comment.

Search

Recent Posts

Recent Comments

OcpSoft Agile Management

Recent Tweets:

Posting tweet...

Sponsored By:

Resources

Meta