cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Berens" <>
Subject RE: COCOON-1978
Date Wed, 03 Oct 2007 12:06:55 GMT
The problem is that the JexlContext jc returns a java.util.Map vars via its
method getVars() from which the expression.evaluate method gets its
variables via vars.get(key). As a Map returns null, if the key does not
exist in the Map, there is no way to distinguish between a variable with a
null value and a non-existent variable.
A possible way to solve this is to write an own implementation of the
JexlContext returning an implementation of Map which throws an exception for
non-existent keys. Note however that this is not in accordance with the Java
API for the Map interface. The thing is that the JexlContext returns a Map
of variables i.s.o. implementing an own get(var) method, which does the job
and which can easily be overridden. This would also make it a lot easier to
implement lazy evaluation of variables.

Another possibility would be to change the Jexl implementation, but that
would require some more effort.

Rob Berens

-----Original Message-----
From: Leszek Gawron [] 
Sent: woensdag 3 oktober 2007 11:32
Subject: COCOON-1978

this pure JEXL code:

// mistaken variable name
String jexlExp = "fuu";

org.apache.commons.jexl.Expression expression = 

// Create a context and add data
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("foo", new Foo() );

// Now evaluate the expression, getting the result
Object o = expression.evaluate(jc);

System.out.println( o );

actually produces "null" when no foo variable is found in context 
instead of throwing. JEXL javadoc does not show any direct method to 
change this behaviour. Is there anything we can do?

Leszek Gawron               
CTO at MobileBox Ltd.

View raw message