Results 1 to 2 of 2

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

  1. #1
    Join Date
    Feb 2008
    Posts
    1

    Post 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. #2
    Join Date
    Dec 2012
    Posts
    8

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •