[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-dev
Subject:    Re: Velocity Tools kills spring macros
From:       "Paul Sundling (Webdaddy)" <tkz () tkz ! net>
Date:       2009-01-25 23:28:06
Message-ID: 497CF586.9080202 () tkz ! net
[Download RAW message or body]

  <bean id="league.servlet.viewResolver"
    
class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
    <property name="order" value="2"/>
    <property name="suffix" value=".vm"/>
    <property name="redirectHttp10Compatible" value="false"/>
    <property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml"/>
    <!-- variable to override layoutUrl -->
    <property name="layoutKey" value="layout"/>
    <property name="layoutUrl" value="layout/webStandard.vm"/>
    <property name="screenContentKey" value="screen_content"/>
    <property name="exposeRequestAttributes" value="true"/>
    <property name="exposeSessionAttributes" value="true"/>
    <!-- Uses spring macros from 
org.springframework.web.servlet.view.velocity
    package    in spring-webmvc so they don't have to be configured -->
    <property name="exposeSpringMacroHelpers" value="true"/>
  </bean>

Here is how I have it configured in Spring MVC.  The toolbox.xml is just 
the same as the example, it even has your author element in the file 
still.  I would normally sent such questions to a user list, but when 
just changing the beta point release was enough to break it, I figured 
it was either a bug or a deprecation I didn't notice.

Paul Sundling
http://www.gamerleague.com

Nathan Bubna wrote:
> I'm not sure what's going on here.  How are you configuring your
> tools?  How are you processing the templates?  If
> $springMacroRequestContext.class has no value, that means that
> $springMacroRequestContext is not in the velocity context being merged
> with the template.  I can't recall any difference between beta1 and
> beta2 that would change that, but i wouldn't rule it out as there were
> plenty of changes.  Still, without knowing more about how you have
> Velocity, VelocityTools and Spring MVC configured to interact, it is
> hard to know why you aren't getting that object in your context
> anymore.
>
> On Mon, Jan 5, 2009 at 2:17 AM, Paul Sundling (Webdaddy) <tkz@tkz.net> wrote:
>   
>> 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: dev-unsubscribe@velocity.apache.org
>>> For additional commands, e-mail: dev-help@velocity.apache.org
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: dev-help@velocity.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
> For additional commands, e-mail: dev-help@velocity.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic