title: SPEL (Spring Expression Language) Collection Selection calling methods/functions in selection
body: <p>I am trying to write simple validation rules with SpEL</p>
  
  <p>I want to be able to say something like, "Do any elements in the List have a value greater then x". Simple case works fine, but I wanted to extend it to get the absolute value first and then do the greater than test</p>
  
  <p>If I try to call methods or functions as part of the criteria to select from a collection. it seems to loose the context that I am working with an item in the collection</p>
  
  <pre><code>import java.util.Arrays;
  import java.util.List;
  
  public class BeanClass {
  
      private final List&lt;ListOf&gt; list;
  
      public BeanClass(ListOf... list){
          this.list = Arrays.asList(list);
      }
  
      public List&lt;ListOf&gt; getList(){
          return list;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class ListOf {
      private final double value;
  
      public ListOf(double v) {
          this.value = v;
      }
  
      public double getValue() {
          return value;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>import org.junit.Test;
  import org.springframework.expression.Expression;
  import org.springframework.expression.ExpressionParser;
  import org.springframework.expression.spel.standard.SpelExpressionParser;
  
  import static org.junit.Assert.assertTrue;
  
  public class SpelTest {
  
      @Test
      public void test(){
          ExpressionParser parser = new SpelExpressionParser();
  
          // works as expected
          Expression expression1 = parser.parseExpression("list.?[ value&gt;2 ].size()!=0");
          assertTrue(expression1.getValue(new BeanClass(new ListOf(1.1), new ListOf(2.2)), Boolean.class));
  
          Expression expression2 = parser.parseExpression("list.?[ T(java.lang.Math).abs(value) &gt; 2 ].size()!=0");
  
          // get this error:
          //org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 5): Property or field 'value' cannot be found on object of type 'BeanClass' - maybe not public?
          assertTrue(expression2.getValue(new BeanClass(new ListOf(1.1), new ListOf(-2.2)), Boolean.class));
      }
  }
  </code></pre>
  
  <p>I have played with defining my own function and registering it</p>
  
  <p>Experimented with #this as well</p>