Using Velocity Toolbox Features in Spring

Today the need to URL encode some URLs within a Velocity view came up in a Spring application of mine. After a few failed attempts to get a LinkTool working, I found the issue. There was a problem with the formatting of my toolbox.xml file. I thought I'd better recap the complete setup for using Velocity toolbox views in Spring.

First, I define a VelocityViewResolver in my servlet beans configuration file (spring-servlet.xml). I define a
toolboxConfigLocation, and set it to /WEB-INF/classes/toolbox.xml. I change the viewClass to use the VelocityToolboxView class instead of VelocityView. Here's an excerpt of the important area:


rc
true
/WEB-INF/classes/toolbox.xml
dateTool
numberTool
formatter
org.springframework.web.servlet.view.velocity.VelocityToolboxView
.vm

Then, I created a toolbox.xml file in a directory that ends up placing files in /WEB-INF/classes (conf/all) to be exact. Here is the complete file:


true


link
request
org.apache.velocity.tools.view.tools.LinkTool


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.

More information about formatting options