I found another bug in the SpEL documentation.
On this page:
http://static.springsource.org/sprin....html#d0e11738
Where it says:
Code:
String randomPhrase =
parser.parseExpression("random number is ${T(java.lang.Math).random()}",
new TemplatedParserContext()).getValue(String.class);
It should say:
Code:
String randomPhrase =
parser.parseExpression("random number is ${T(java.lang.Math).random()}",
new TemplateParserContext()).getValue(String.class);
In short 'Templated' should be 'Template'.
Under which category in Jira should such bugs be reported? I didn't see one for SpEL.
Update: Actually I realised that this is not a mistake. I mistook TemplatedParserContext for TemplateParserContext in the SpEL API. I hadn't realised that it was expected that the user define his own context here. I'm curious - how come a ready made expression templating context wasn't provided out of the box and a standard wasn't set for the prefix and suffix for templating?
On that note is there a more succinct way of doing the following?
Code:
@Test
public void testExpressionTemplating() {
String fooBarBaz = parser.parseExpression("foo ${'foobar'.substring(3)} ${'barbaz'.substring(3)}",
new ParserContext() {
public String getExpressionPrefix() {
return "${";
}
public String getExpressionSuffix() {
return "}";
}
public boolean isTemplate() {
return true;
}
}).getValue(String.class);
System.out.println(fooBarBaz);
assertEquals("foo bar baz", fooBarBaz);
}
Would be nice to have a more succinct way of specifying prefix and suffix.
Thanks.