"Velocity is Java based template engine..."
Integration with Velocity is done through VelocityViewAdapter . It is a view implementation used by MVCConnectionHandler .
VelocityViewAdapter obtains template from supplied view name (using suffix if supplied) and processes it using a model that is passed in.
VelocityViewAdapter
has three parameters: templatesLocation
, suffix
and contentType
.
The first is self-explanatory, while the second represents a string that is suffixed to the template name
supplied by
ModelAndView
. Suffix
can be set to null
and in that case it is going to be treated as suffix
is set
to ""
. ContentType
is used as default content type for returned
rendered pages.
VelocityViewAdapter 's init method must be called before adapter can be used. That method sets default content type and initialises Velocity template engine with AbsoluteFileResourceLoader. Templates' location can be set as a file or URL.
Here is an example of an configuration of Velocity (with Spring Webflow ) taken from supplied demo:
<!-- * This bean defines beans application context. * It references MVC controller defined at the "/guess.do" path. --> <bean name="web-application" class="org.abstracthorizon.danube.http.HTTPContext"> <property name="components"> <list> <bean class="org.abstracthorizon.danube.http.matcher.Prefix"> <property name="prefix"><value>/guess.do</value></property> <property name="connectionHandler"><ref bean="guess.do"/></property> </bean> </list> </property> </bean> <!-- * This is MVC controller that has Spring WebFlow as a controller and Velocity as a view adapter. --> <bean name="guess.do" class="org.abstracthorizon.danube.http.HTTPMVCConnectionHandler"> <property name="controller"><ref bean="webFlowController" /></property> <property name="view"><ref bean="velocityViewAdapter" /></property> </bean> <!-- * This is WebFlow controller. Flow locator is defined through flow registry bean and * "bean-explorer-flow" is set as defualt flow id --> <bean name="webFlowController" class="org.abstracthorizon.danube.webflow.DanubeFlowController"> <property name="flowLocator"><ref bean="flowRegistry" /></property> <property name="defaultFlowId"><value>guess-flow</value></property> </bean> <!-- * Flow registry defines where flow definitions are to be read from. --> <bean id="flowRegistry" class="org.springframework.webflow.registry.XmlFlowRegistryFactoryBean"> <property name="flowLocations" value="guess-flow.xml"/> </bean> <!-- * This is Velocity view adapter. * It defines directory "templates" as location of templates. --> <bean id="velocityViewAdapter" class="org.abstracthorizon.danube.velocity.VelocityViewAdapter" init-method="init"> <property name="templatesLocation"><value>templates</value></property> </bean>