Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Spring View which supports the Velocity Tools 2.0 sub-project. Configured using the Spring Bean xml snippet below.
public class VelocityTools2View extends VelocityLayoutView {
private ViewToolManager toolManager;
protected Context createVelocityContext (Map<String, Object> model,
HttpServletRequest request,
HttpServletResponse response) {
ToolContext toolContext = toolManager.createContext(request, response);
VelocityContext context = new VelocityContext(toolContext);
if (model != null) context.putAll(model.entrySet());
return context;
public void afterPropertiesSet() throws Exception {
XmlFactoryConfiguration config = new XmlFactoryConfiguration();;
boolean autoConfigure = false;
boolean includeDefaults = false;
toolManager = new ViewToolManager(getServletContext(), autoConfigure, includeDefaults);
<bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
<property name="viewClass" value="com.eo3.lib.spring.VelocityTools2View"/>
<property name="toolboxConfigLocation" value="/WEB-INF/velocity-tools.xml"/>
Copy link

bendilley commented Jan 16, 2013

Note that

  • I'm extending the VelocityLayoutView but could equally extend VelocityToolboxView
  • context.putAll(model.entrySet()) was enabled by extending VelocityContext with my own version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment