Results 1 to 6 of 6

Thread: How to configure Velocity Tools for a VelocityEngine?

  1. #1
    Join Date
    Sep 2004
    Location
    Szeged, Hungary
    Posts
    29

    Default How to configure Velocity Tools for a VelocityEngine?

    Hi,

    It may be a simple question, but now I'm dealing with velocity-based emails. I've done the tutorial as Matt Raible discussed.

    I'd like to use the $format.number() velocity tool (results as JSTL <format:number/> tag does). How can I configure the VelocityEngine to use the toolbox.xml?

    Thanks for any help.

    Thomas

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    You can configure DateTool and NumberTool attribute as follows:
    Code:
      <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
        <property name="numberToolAttribute"><value>numberTool</value></property>
        <property name="dateToolAttribute"><value>dateTool</value></property>
        <property name="suffix"><value>.vm</value></property>
      </bean>
    and in you velocity templates you use:
    Code:
    $dateTool.format&#40;&#41;
    $numberTool.format&#40;&#41;
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Sep 2004
    Location
    Szeged, Hungary
    Posts
    29

    Default

    Thanks Omar. One more question? Can you help me on how I could set only the VelocityEngine to use the numberTool. I have only a VelocityEngine in my mail-velocity-merging manager, so I'm not having any view resolver - cannot have here a VelocityViewResolver.

    UPDATE 1
    Finally solved. I found that velocity tools are added simply into the velocity context, that is based on the map model passed to velocityEngine.mergeTemplate() method.

    Thomas

  4. #4
    Join Date
    May 2007
    Posts
    2

    Default

    Could somebody who has done this post an example, please?

    If I have:

    Code:
    result = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, model);
    where model is a Map consisting of parameter names and their values that will be passed to Velocity, how do I specify tools? What would their names and values be that I place in the map?

    Thanks.

  5. #5
    Join Date
    May 2007
    Posts
    2

    Default

    Okay I think I figured it out. I just create a tool object, either via spring config or programatically, add it to my model Map like:

    Code:
    map.put("toolName", tool);
    And then access the tool using toolName in the template like any other parameter.

    I'll be trying it at work tomorrow, but feel free to correct me if I'm wrong.

  6. #6
    Join Date
    Oct 2009
    Posts
    1

    Wink try this one, then u can use your code

    Quote Originally Posted by jbodnar View Post
    Could somebody who has done this post an example, please?

    If I have:

    Code:
    result = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, model);
    where model is a Map consisting of parameter names and their values that will be passed to Velocity, how do I specify tools? What would their names and values be that I place in the map?

    Thanks.

    <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEng ineFactoryBean">
    <property name="velocityProperties">
    <value>
    resource.loader=class
    class.resource.loader.class=org.apache.velocity.ru ntime.resource.loader.ClasspathResourceLoader
    </value>
    </property>
    </bean>

Similar Threads

  1. How to configure Velocity tools?
    By alr in forum Web
    Replies: 7
    Last Post: Jan 31st, 2007, 09:38 AM
  2. Replies: 0
    Last Post: Jul 13th, 2005, 02:43 AM
  3. Velocity OutOfMemoryError during UnitTests
    By camach in forum Container
    Replies: 2
    Last Post: May 26th, 2005, 05:28 PM
  4. How to use Velocity Tools in Spring
    By yufeng in forum Web
    Replies: 1
    Last Post: Dec 16th, 2004, 07:15 PM
  5. Replies: 2
    Last Post: Sep 5th, 2004, 04:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •