Created
January 16, 2013 18:57
-
-
Save bendilley/4549746 to your computer and use it in GitHub Desktop.
Spring View which supports the Velocity Tools 2.0 sub-project. Configured using the Spring Bean xml snippet below.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class VelocityTools2View extends VelocityLayoutView { | |
private ViewToolManager toolManager; | |
@Override | |
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; | |
} | |
@Override | |
public void afterPropertiesSet() throws Exception { | |
super.afterPropertiesSet(); | |
XmlFactoryConfiguration config = new XmlFactoryConfiguration(); | |
config.read(getServletContext().getResourceAsStream(getToolboxConfigLocation())); | |
boolean autoConfigure = false; | |
boolean includeDefaults = false; | |
toolManager = new ViewToolManager(getServletContext(), autoConfigure, includeDefaults); | |
toolManager.configure(config); | |
toolManager.setVelocityEngine(getVelocityEngine()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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"/> | |
... | |
</bean> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that
context.putAll(model.entrySet())
was enabled by extending VelocityContext with my own version