You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Li Yuzhu <yu...@meridian.com.cn> on 2012/08/22 05:59:10 UTC
[JEXL] How to use it as leg[leftOrRight='left'].length<30 in list and map
Hi
I hava a question about jexl.
for example
package jexl.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.jexl2.JexlContext;
import org.apache.commons.jexl2.JexlEngine;
import org.apache.commons.jexl2.MapContext;
public class Test {
public static void main(String[] args) {
Map<String, Object> person=new HashMap<String, Object>();
Map<String, Object> leg1=new HashMap<String, Object>();
leg1.put("leftOrRight", "left");
leg1.put("length", 20.3);
Map<String, Object> leg2=new HashMap<String, Object>();
leg2.put("leftOrRight", "right");
leg2.put("length", 20.3);
List<Map<String, Object> > legs=new ArrayList<Map<String, Object> >();
legs.add(leg1);
legs.add(leg2);
person.put("leg",legs);
JexlContext context = new MapContext(person);
JexlEngine engine=new JexlEngine();
Boolean yes1=(Boolean)engine.createExpression( "leg[0].length<30" ).evaluate(context);
Boolean yes2=(Boolean)engine.createExpression( "leg[leftOrRight='left'].length<30" ).evaluate(context); // how should i used it?
System.out.println(yes1+","+yes2);
}
}
It displays as follow
true,false
why does the yes2 equals as 'false'? How should i do it?
Li Yuzhu
2012-08-22