Just to clear up what the code does, Here is a simpler version of the
template. It basically uses the spring macro context that is stored
with Spring MVC and outputs the variables. With velocity tools
2.0-beta1, you get the actual answers like the locale. With velocity
tools 2.0-beta2 or 3, you get just the variable name like
$springMacroRequestContext.class, meaning there is no value (which would
be blank if I had $!springMacroRequestContext.class instead...)
<ul>
<li>class => $springMacroRequestContext.class </li>
<li>contextPath => $springMacroRequestContext.contextPath </li>
<li>isDefaultHtmlEscape =>
$springMacroRequestContext.isDefaultHtmlEscape </li>
<li>locale => $springMacroRequestContext.locale </li>
<li>queryString => $springMacroRequestContext.queryString </li>
<li>requestUri => $springMacroRequestContext.requestUri </li>
<li>theme.name => $springMacroRequestContext.theme.name </li>
<li>webApplicationContext =>
$springMacroRequestContext.webApplicationContext </li>
</ul>
Paul Sundling
Paul Sundling (Webdaddy) wrote:
I noticed that my spring macros stopped working. I narrowed down the
cause to a version of velocity tools. Just changing what version of
velocity tools made the difference. So what changed between 2.0-beta1
and 2.0-beta2 to cause the failure? I assume I'm not the only one on
the list using Spring MVC with velocity.
Here are the maven pom changes to switch between working and failing
versions.
WORKS:
<dependency>
<groupId>velocity-tools</groupId>
<artifactId>velocity-tools</artifactId>
<version>2.0-beta1</version>
</dependency>
FAILS:
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<version>2.0-beta3</version><!-- 2.0-beta2 also fails -->
</dependency>
The version of spring MVC used was 2.5.5 or 2.5.6
Here is the code snippet:
#macro(collectionAsList $name $collection)
<b>$name</b><br/>
<ol>
#foreach($element in $collection)
<li>$element</li>
#end
</ol>
#end
#macro(evalFieldList $evalVar $fieldList)
<ul>
#foreach($evalField in $fieldList)
<li> $evalField => $render.eval("${evalVar}.$evalField") </li>
#end </ul> #end
<b>springMacroRequestContext ($springMacroRequestContext.class)</b>
#set($requestContextFields = ['contextPath', 'isDefaultHtmlEscape()',
'locale', 'queryString',
'requestUri', 'theme.name', 'webApplicationContext'])
#evalFieldList('$springMacroRequestContext', $requestContextFields)
Let me know if you need anything more.
Paul Sundling
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]