How do I call an object’s method from EL?
Give the object:
public class TestObj {
public testObj() { };
public String test() { return "foo"; }
public String someOtherMethod(String param) { return param + "_bar"; }
}
and the obj is added to the pageContext
pageContext.setAttribute("t", new TestObj());
How would I perform the equivalent of:
<%= t.test() %>
<%= t.someOtherMethod("foo") %>
using EL?
It’s supported since EL 2.2 which has been out since December 10, 2009 (over 2.5 years ago already!). EL 2.2 goes hand in hand with Servlet 3.0, so if you target a Servlet 3.0 container (Tomcat 7, Glassfish 3, etc) with a Servlet 3.0 compatible
web.xmlwhich look like followsthen you’ll be able to invoke methods with or without arguments in EL in the following forms: