Velocity
Velocity is a Java-based template framework which provides the default HTML rending engine
for Click. Velocity is very easy to learn, simple to use, and is also very capable.
Velocity is an open source
Apache project licensed using the Apache Software License.
Velocity's comprehensive online documentation is included in this distribution.
Object References
With Click you add objects to your page template using the Page's model. You can then access these objects
using Velocities $ reference notation. By default the ClickServlet adds the
following objects to page templates:
-
any public Page fields using the fields name
- context -
the Servlet context path, e.g. /mycorp
- cssImports -
the CSS imports and style blocks to include in the pages header.
Please see PageImports
for more details.
- format -
the Format
object for formatting the display of objects.
- imports -
the CSS and JavaScript imports to include in the pages header.
Please see PageImports
for more details.
- jsImports -
the JavaScript imports and script blocks to include in the pages footer.
Please see PageImports
for more details.
- messages -
the MessagesMap adaptor
for the Page getMessage()
method.
- path -
the path
of the page template to render.
- request -
the pages HttpServletRequest
object.
- response -
the pages HttpServletResponse
object.
- session -
the SessionMap adaptor
for the users HttpSession.
In your page templates you can access object references using a dot path notation. For example:
Welcome: $session.user.fullName
Or by using a more explicit Java notation:
Welcome: $session.get("user").getFullName()
Directives
In Velocity directives are prefixed by a # symbol. While
references access stuff, directives do stuff. The full set of Velocity directives are:
- #if #elseif #else -
output conditional on truth of statements.
- #foreach -
loops through a list of objects.
- #macro -
allows users to define a Velocimacro (VM), a repeated segment of a VTL template, as required.
- #set -
establishes the value of a reference.
- #include -
renders local file(s) that are not parsed by Velocity.
- #parse -
renders a local template that is parsed by Velocity.
- #stop -
stops the template engine.