JSF2: How to add the magic of EL (EL2) to JSF
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> |
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.
Hi!
Thanks for this article! i tried to add the new EL to my Struts project which is working with JSPs AND JSF/facelets (this is working all right, no problem there). But when i put the context-param for the new ELFactory in web.xml and call my facelets-page it logs: “The ELResolvers for JSF were not registered with the JSP-Container” and all EL-strings on the page are ignored.
Any idea where this might come from?!
I’m using tomcat 6 and the JSF2.0 reference implementation.
Thx in advance!
Hi, Lincoln. I try this on top of Tomcat 6 and spring 3. Unfortunately I cannot get it works. I’m still always get java.lang.NoSuchMethodError: javax.el.ELResolver.invoke() . Can you help for this?
Thanks.
@xsalefter
remove el-api.jar from tomcat6 /lib directory or use tomcat7 without requiring explaned above.
[…] 原文参考链接:http://ocpsoft.com/java/jsf2-java/jsf2-how-to-add-the-magic-of-el-el2-to-jsf/ […]
To get this working on Weblogic 10.3 I had to include the following lines in my weblogic-application.xml:
com.sun.el.*
javax.el.*
well that still did not work…… the tags are
wls:prefer-application-packages
wls:package-name com.sun.el.* /wls:package-name
wls:package-name javax.el.* /wls:package-name
/wls:prefer-application-packages
I’m trying out this as well… figuring how to add EL 2.2 to Weblogic 10.3.4.
Do you have to replace/remove any libs in WL?
I did not have to remove any libs, but I had to declare the entries (see above) for wls:prefer-application-packages in weblogic-application.xml.
I just put the two jars (which I downloaded manually; I’m not using maven) into my WebContent/WEB-INF/lib. Declared the web.xml entry (as in the above article) and declared the prefer-application-packages entries. After all that it worked on WL 10.3.3.
Hmm, I’m getting the following exceptions; seems like I need to do some JSP lib stuffs?
“com.sun.faces.config.ConfigurationException: It appears the JSP version of the container is older than 2.1 and unable to locate the EL RI expression factory, com.sun.el.ExpressionFactoryImpl. If not using JSP or the EL RI, make sure the context initialization parameter, com.sun.faces.expressionFactory, is properly set.”
Hmm, my bad, some typo in the config file. EL2.2 seems to be working now… however, now I’m getting JSF1027: [null] The ELResolvers for JSF were not registered with the JSP.
Did you get this? I wonder what are the side effects.
you forgot to mention that this article is for glassfish container, and for using exactly EL 2.2 since above is not valid in EL 2.1 AFAIK.
to use EL 2.2 with tomcat, you can use the EL 2.2 shipped with tomcat 7 and add the EL dependency in pom and mark it as provided, hope that will help anyone.
[…] this post from Lincoln Baxter I downloaded el-api-2.2.jar and […]