This simple program using OGNL returns me a list of null values instead of [A,B,D]. I've tried #root{#x.get(#this)}
and still returns me a list of nulls. Why? Thanks.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ognl.Ognl;
public class ognlTest {
static public void main(String[] args) throws Exception
{
Map<String, Object> m = new HashMap<String, Object>();
m.put("a", "A");
m.put("b", "B");
m.put("c", "C");
m.put("d", "D");
List<String> k = new ArrayList<>();
k.add("a");
k.add("b");
k.add("d");
Map<String, Object> context = new HashMap<String, Object>();
context.put("x", m);
Object expression = Ognl.parseExpression( "#root.{ #x[#this] }");
Object value = Ognl.getValue( expression, context, k);
System.out.println("value = [" + value + "]");
}
}
Update:
Use #root.{#z=#this, #x[#z]}
. Silly but it works. I believe this is a bug but Apache OGNL 4 is in limbo and OGNL 3.0.6 is ... I'm not sure it is maintained; the distribution doesn't even compile because it has wrong dependencies.