Getting Started

Here's all you need to use the EL in your application (assuming you added juel-2.1.x.jar to your classpath and did import javax.el.*):

  1. Factory and Context
    // the ExpressionFactory implementation is de.odysseus.el.ExpressionFactoryImpl
    ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl();
    
    // package de.odysseus.el.util provides a ready-to-use subclass of ELContext
    de.odysseus.el.util.SimpleContext context = new de.odysseus.el.util.SimpleContext();
  2. Functions and Variables
    // map function math:max(int, int) to java.lang.Math.max(int, int)
    context.setFunction("math", "max", Math.class.getMethod("max", int.class, int.class));
    
    // map variable foo to 0
    context.setVariable("foo", factory.createValueExpression(0, int.class));
  3. Parse and Evaluate
    // parse our expression
    ValueExpression e = factory.createValueExpression(context, "${math:max(foo,bar)}", int.class);
    
    // set value for top-level property "bar" to 1
    factory.createValueExpression(context, "${bar}", int.class).setValue(context, 1);
    
    // get value for our expression
    System.out.println(e.getValue(context)); // --> 1