Here is an example of using both a velocity view resolver and an internal view resolver. In addition, I have derived spring VelocityLayoutView to be able to use velocity tools in version 2.0. Order is 10 for velocity resolver and 20 for internal to give velocity resolver a chance to resolve its view before the internal resolver that allways resolve. Output is forced to UTF-8 for velocity views.
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="viewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="20">
</bean>
<bean class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver"
id="vmViewResolver" p:order="10" p:suffix=".vm" p:prefix=""
p:cache="true" p:contentType="text/html;charset=UTF-8"
p:exposeRequestAttributes="false" p:exposeSessionAttributes="false"
p:exposePathVariables="true" p:exposeSpringMacroHelpers="true"
p:dateToolAttribute="date" p:toolboxConfigLocation="/WEB-INF/toolbox.xml"
p:viewClass="org.sba.views.Velocity2LayoutView">
<property name="attributesMap">
<map>
<entry key="messageSource" value-ref="messageSource"/>
</map>
</property>
</bean>
And here is the modified VelocityView :
public class Velocity2LayoutView extends VelocityLayoutView {
ViewToolManager toolManager;
@Override
protected Context createVelocityContext(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) throws Exception {
ViewToolContext context = toolManager.createContext(request, response);
context.putAll(model);
return context;
}
@Override
protected void initTool(Object tool, Context velocityContext) throws Exception {
}
@Override
public void afterPropertiesSet() throws Exception {
toolManager = new ViewToolManager(getServletContext(), false, false);
if (getToolboxConfigLocation() != null) {
XmlFactoryConfiguration config = new XmlFactoryConfiguration();
config.read(getServletContext()
.getResourceAsStream(getToolboxConfigLocation()));
toolManager.configure(config);
}
toolManager.setVelocityEngine(getVelocityEngine());
}
}