commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Li Yuzhu" <yuzhu...@meridian.com.cn>
Subject [JEXL] How to use it as leg[leftOrRight='left'].length<30 in list and map
Date Wed, 22 Aug 2012 03:59:10 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message