Announcement Announcement Module
Collapse
No announcement yet.
Spring Expression Language:: Look up in a map for every value in a collection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Expression Language:: Look up in a map for every value in a collection

    I've following code:

    PHP Code:
    @Test
       
    public void testCollection()
      {
        List<
    Stringl= new ArrayList<String>();
        
    l.add("S1");
        
    l.add("S2");
        
    Map<StringString= new HashMap<StringString>();
        
    m.put("S1","M1");
        
    m.put("S2","M2");
        
       
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
        
    evaluationContext.setVariable("l",l);
        
    evaluationContext.setVariable("m",m);
        
        
    ExpressionParser expressionParser = new SpelExpressionParser();
        
        
    String expression1 "#l.![#this]";
        
    // This one prints S1,S2
        
    System.out.println(expressionParser.parseExpression(expression1).getValue(evaluationContext,String.class));
        
        
    String expression2 "#l.![#m[#this]]";
        
    // This one prints null, null and I expect M1,M2
        
    System.out.println(expressionParser.parseExpression(expression2).getValue(evaluationContext,String.class));
      } 
    The question is why expression2 is evaluated to null,null and not M1,M2 or generally how do I get a collection of values projected by looking up in a map using collection entries as keys?

  • #2
    I tried this "#m.?[#l.contains(key)].keySet()".
    but cannot work

    Comment

    Working...
    X