Method Expressions

Method expressions can be "invoked". A javax.el.MethodExpression is invoked by calling its invoke(ELContext, Object<?>[]) method. The specification also allows to treat literal text as a method expression.

A method expression is called a literal method expression if its underlying expression is literal text (that is, isLiteralText() returns true). All other method expressions are called non-literal method expressions. Non-literal method expressions share the same syntax as lvalue expressions.

For literal method expressions

On the other hand, non-literal method expressions refer to a java.lang.reflext.Method which can be invoked or used to create a javax.el.MethodInfo instance. For non-literal method expressions

Tree Method Expressions

Class de.odysseus.el.TreeMethodExpression is a subclass of javax.el.MethodExpression, which is used by JUEL to represent method expressions. It is the return type of

ExpressionFactoryImpl.createMethodExpression(ELContext, String, Class<?>, Class<?>[])

In addition to the methods declared by javax.el.MethodExpression, it provides

  • void dump( writer) – dump parse tree
  • boolean isDeferred()true if expression is deferred (contains eval expressions #{...})
import de.odysseus.el.*;
import de.odysseus.el.util.*;
ExpressionFactoryImpl factory = new ExpressionFactoryImpl();
SimpleContext context = new SimpleContext(); // more on this here...
TreeMethodExpression e =
  factory.createMethodExpression(context, "#{x.toString}", String.class, new Class[]{});
PrintWriter out = new PrintWriter(System.out);
// +- #{...}
//   |
//   +- . toString
//      |
//      +- x
System.out.println(e.isDeferred()); // true