3

A JEXL Script is not the same as a JEXL Expression.

I see references to functions in the source code, but I see no documentation about it. Has it maybe not been implemented yet?

There is a JSR-223 interface for it.

Sarel Botha
  • 12,419
  • 7
  • 54
  • 59

1 Answers1

1

If you need to defined functions, then you should use the JexlEngine#setFunctions(Map namespace2FunctorMap). See the Javadoc (currently down ;-( )

If you need methods, then you should add to your JexlContext the objects having the methods you want to call. See "calling methods" in this page.

Under the hood, Jexl uses reflection to call methods if I can properly remember.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
S. Cambon
  • 560
  • 3
  • 9
  • Neat. So that allows you to define top-level functions. It's like static import in Java. I think I was trying to see if you can write the function code in JEXL, not just call a function or method written in Java. – Sarel Botha Sep 25 '12 at 22:29
  • I don't think that Jexl currently allows defining new functions in a script. You could trick it by preprossessing your file to extract the functions code, wrap it into Java objects and register them to the engine. – S. Cambon Sep 26 '12 at 04:56