diff --git a/spring-framework-reference/src/expressions.xml b/spring-framework-reference/src/expressions.xml index cb0aa3267f5..936f6cb2a0a 100644 --- a/spring-framework-reference/src/expressions.xml +++ b/spring-framework-reference/src/expressions.xml @@ -97,11 +97,15 @@ User defined functions - + + + Collection selection + + Templated expressions @@ -253,7 +257,39 @@ boolean result = exp.getValue(context, Boolean.class); // evaluates to true Type Conversion - TODO + By default SpEL uses the conversion service available in + Spring core (org.springframework.core.convert.ConversionService). + This conversion service comes with many converters built in for common conversions + but is also fully extensible so custom conversions between + types can be added. Additionally it has the key capability that it + is generics aware. This means that when working with generic types in + expressions, SpEL will attempt conversions to maintain type correctness for any + objects it encounters. + + + What does this mean in practice? Suppose assignment, using setValue(), + is being used to set a List property. The type of the property is + actually List<Boolean>. SpEL will recognize that the elements + of the list need to be converted to Boolean before being placed in it. + A simple example: + + class Simple { + public List<Boolean> booleanList = new ArrayList<Boolean>(); +} + +Simple simple = new Simple(); + +simple.booleanList.add(true); + +StandardEvaluationContext simpleContext = new StandardEvaluationContext(simple); + +// false is passed in here as a string. SpEL and the conversion service will +// correctly recognize that it needs to be a Boolean and convert it +parser.parseExpression("booleanList[0]").setValue(simpleContext, "false"); + +// b will be false +Boolean b = simple.booleanList.get(0); + @@ -677,12 +713,12 @@ parser.parseExpression("Name = #newName").getValue(context); System.out.println(tesla.getName()) // "Mike Tesla" - +
@@ -759,23 +812,56 @@ String queryResultString = parser.parseExpression(expression).getValue(societyCo // queryResultString = "Nikola Tesla is a member of the IEEE Society"
-
Expression templating