Main Tutorials

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 Author

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

Comments

Subscribe
Notify of
14 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
vvid
9 years ago

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
8 years ago
Reply to  vvid

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
10 years ago

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 starters is that they think that this new EL 2.2 syntax is specific to JSF 2.0. But this is thus actually not true. This confusion is caused because both EL 2.2 and JSF 2.0 are part of Java EE 6, but JSF 2.0 itself is backwards compatible with Java EE 5 (Servlet 2.5, EL 2.1, etc).

reference http://stackoverflow.com/questions/10988250/running-jsf-page-error-failed-to-parse-the-expression-logmodel-getloglist

Raghavendra
11 years ago

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
11 years ago

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
11 years ago

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
11 years ago

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.

Ashish
12 years ago

i am using jboss

geting error that el does not support method with parameter

jai
13 years ago

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

alx
13 years ago
Reply to  mkyong

Hello,
i have the same problem with my project[and the same error]. Sorry, can you be more explicit and explain how to include “javaee.jar” in netbeans class path..?

Raju Ilayaraja
12 years ago
Reply to  alx

Hi MKYong,

I am running this application in weblogic server. I am also hitting the same error. method parameter passing is not working. I added j2ee.jar also. No Luck!!!

Can you help me? Any Idea?

Regards,
Ilaya

alx
13 years ago
Reply to  alx

i try to add javaee.jar from project -> right click proprietes -> Compile -> addJar, i put “javaee.jar” and pressed Save.I select clear and build,run and nothing, the same error. Why? 🙁 I wrong somewhere?
And this file “pom.xml” with this code :
org.glassfish.web
el-impl
2.2

where should be added?
Tnx