How to pass parameters in method expression – JSF 2.0

Since JSF 2.0, you are allow to pass parameter values in method expression like “#{bean.method(param)}“, but this feature will raising a “EL parsing error” on Tomcat server. For example,

Managed Bean


@ManagedBean(name="order")
@SessionScoped
public class OrderBean implements Serializable{
	
	public String editAction(String id) {
		//...
	}
}

JSF page


//...
<h:commandLink value="Edit" action="#{order.editAction(123)}" />
//...

If deployed on Tomcat, it will hits following error messages :


An Error Occurred:
Error Parsing: #{order.editAction(123)}

or


javax.el.MethodNotFoundException

Solution

Actually, this so call “method expression parameters” is a feature of EL 2.2, which is NOT support in Tomcat by default.

In order to use this feature, you have to get “el-impl-2.2.jar” from Java.net, and put it into your project dependencies folder.

File : pom.xml


     <dependency>
	  <groupId>org.glassfish.web</groupId>
	  <artifactId>el-impl</artifactId>
	  <version>2.2</version>
     </dependency>

Done, Tomcat should be able to support method expression parameters in JSF 2.0 web application.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
vvid
Guest
vvid

How to pass a tag like action=”#{order.editAction(#{order.orderObject})}” in the action where I have a method like editAction(Order order) in the backing bean?

Mjetz
Guest
Mjetz

This syntax is not valid. Instead, try #{order.editAction(order.orderObject)}. But even then, I’m not sure this makes sense. It seems like you’re trying to use the same class as both a bean and a business object.

shareef
Guest
shareef
The EL syntax ${LogModel.getLogList()} is only supported since EL 2.2 which goes along with Servlet 3.0. But you’re using the old Tomcat 6 server which is a Servlet 2.5 container which implies EL 2.1. You need to use the normal EL 2.1 syntax then. ${LogModel.logList} If you really insist in using the new EL 2.2 syntax of invoking action methods, then you could always install JBoss EL as described in this answer: JSF 2.0 method invocation However, this makes no sense for a simple getter method which could then be accessed by a simpler EL syntax. A major misconception among… Read more »
Raghavendra
Guest
Raghavendra

Hi Mkyong,

I am using eclipse ide and tomcat 6 server. I followed the above steps included el-impl2.2 jar in lib directory of the project and configured the build path but same error is existing for me…plzz provide me solution for this!!!!!… FYI iam not using maven dependecny.

Thanks
Raghavendra

Cássio Nandi Citadin
Guest
Cássio Nandi Citadin

You site has been very helpful on my day to day development, thank you!

Have you any idea on how to put this to work on Websphere 7? I did what you told about Tomcat, but not worked on WS as expected.

Cássio Nandi Citadin
Guest
Cássio Nandi Citadin

This is my library

el-impl-2.2.jar
jsf-api.jar
jsf-impl.jar
jstl-api-1.2.jar
jstl-impl-1.2.jar
log4j-1.2.11.jar

I configured the EAR from RAD (Eclipse from IBM) to load libs from the project first (PARENT_LAST), so, it will load my libs before original WebSphere.

js
Guest
js

I don’t know you you find these esoteric solutions, but I certainly do appreciate your web pages. This simple update to pom.xml solved my problem.

trackback
JSF2 – EL passing parameter in method, hits javax.el.MethodNotFoundException

[…] <version>2.2</version> </dependency> Note Similar issue – JSF2 – pass parameters in method expression This article is under – JSF 2 Tutorials , Tags: jsf2 mkyong Founder and Chief Editor […]

Ashish
Guest
Ashish

i am using jboss

geting error that el does not support method with parameter

jai
Guest
jai

An Error Occurred:

/default.xhtml @54,75 action=”#{order.deleteAction(o)}” Error Parsing: order.deleteAction(o)}
+- Stack Trace

javax.faces.view.facelets.TagAttributeException: /default.xhtml @54,75 action=”#{order.deleteAction(o)}” Error Parsing: #{order.deleteAction(o)}
at com.sun.faces.facelets.tag.TagAttributeImpl.getMethodExpression(TagAttributeImpl.java:225)

hello sir

i added “el-impl-2.2.jar” to lib folder

but still i am getting the same error parsing for method expression
for the given line only

plz give me some hint to solve the problem as i am using

netbeans 6.8 with jsf 2.0

trackback
4 ways to pass parameter from JSF page to backing bean

[…] Backing bean… @ManagedBean(name="user") @SessionScoped public class UserBean{   public String editAction(String id) { //id = "delete" }   } Note If you are deploy JSF application in servlet container like Tomcat, make sure you include the “el-impl-2.2.jar” properly. For detail, please read this article – JSF 2.0 method expression caused error in Tomcat. […]