Overview¶
VelocityView includes all of the GenericTools and adds infrastructure and specialized tools for using Velocity in the view layer of web applications (Java EE projects). This includes the VelocityViewServlet or VelocityLayoutServlet for processing Velocity template requests and the VelocityViewTag for embedding Velocity in JSP.
Key features:
- VelocityViewServlet - standalone servlet that renders Velocity templates. Invoked directly from web clients requests, or via servlet forwarding similar to how JSP files are rendered by JSPServlet.
- The HttpServletRequest, HttpSession, ServletContext, and their attributes are automatically available in your templates.
- Tools can also be made available to your templates, through a tools configuration file.
- A number of useful, extendable tools for developing web applications are already provided for your convenience.
- Logging is made through the SLF4J logging facade. It can be directed to the log infrastructure of the Web application (using the logging facility provided by the Servlet API) by addind the webapp slf4j logger into the classpath.
Installation¶
For inclusion in a Maven project, use the following dependency block:
<dependency> <groupId>org.apache.velocity.tools</groupId> <artifactId>velocity-tools-view</artifactId> <version>3.0</version> </dependency>
Otherwise, see the download page for how to get the Velocity View Tools jar.
Default Configuration¶
The default configuration provided for VelocityView is here.
Dependencies¶
The dependencies required for VelocityView can be found on our dependencies chart.
VelocityView Object¶
The VelocityView object forms the core of the VelocityView infrastructure. In particular, it serves as the base class for the following:
VelocityViewServlet¶
The VelocityViewServlet class is a standalone servlet that renders Velocity templates. It can be invoked directly from web client's requests, or via servlet forwarding similar to how JSP files are rendered by JSPServlet.
Detailed documentation is here.
VelocityLayoutServler¶
One derivative of the VelocityViewServlet is the [VelocityLayoutServlet](view-layoutservlet.html. This servlet performs a simplified 'two-pass render' in order to apply a shared, common layout to all of the web pages in an application.
The VelocityLayoutServlet also allows you to specify an 'error' template to be displayed when an exception is thrown during the processing of a requested template. This allows you to provide a customized error screen for a more user-friendly application.
Detailed documentation is here.
VelocityViewTag¶
This is a JSP tag that allows you to use Velocity and VelocityTools from within your JSP tags and files. This tag can both process templates in separate files, VTL in the tag body, or combine the two.
Detailed documentation is here.
Tools¶
Please consult the Standard Tools page for a list of standard view tools.
Examples¶
In the VelocityTools sources tree, you will find three examples:
- velocity-tools-simple: a minimalist web application.
- velocity-tools-showcase: a demonstration of all standard tools.
To run the showcase application locally, run the following command from the velocity-tools-examples/velocity-tools-examples-showcase directory:
mvn cargo:run
Then point your browser to:
http://localhost:8080/velocity-tools-examples-showcase/
Logs go to:
velocity-tools-examples/velocity-tools-examples-showcase/target/cargo/configurations/jetty8x/logs/2016_11_05.stderrout.log