commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henrib <>
Subject Re: [jexl] custom expressions / registering functions
Date Wed, 26 May 2010 11:44:34 GMT

JEXL should be appropriate feature-wise; adding EL capabilities to a
framework is one of its intents.

JEXL 2.0 allows to invoke any method on an object accessible through the
evaluation context.
It also allows to register functions in namespaces achieved by mapping the
namespace name to an instance or a class - if all methods are static.

            public static MyMath {
                public double cos(double x) {
                    return Math.cos(x);
            Map<String, Object> funcs = new HashMap<String, Object>();
            funcs.put("math", new MyMath());
            JexlEngine jexl = new JexlEngine();

            JexlContext jc = new MapContext();
            jc.set("pi", Math.PI);

            e = JEXL.createExpression("math:cos(pi)");
            o = e.evaluate(jc);

Useful links on the topic:  (method calls,

Follow-up if things aren't clear enough;

View this message in context:
Sent from the Commons - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message