XpdWiki

FrontPage
RecentChanges
XtC
FindPage
PageIndex
XpApprentices

Set your name in
UserPreferences

Edit this page

Referenced by
FreeMarker
JspAlternatives
VPP




JSPWiki v2.0.52


JakartaVelocity


Velocity is a Java-based template engine. It was primary designed for generating dynamic HTML pages in Web applications that follow MVC (Model-View-Controller) design pattern. This means that the presentation and the Java code are separated. The Java program makes the dirty/complex work, and the page templates are kept stupid simple and concentrate on the presentation. An example Velocity template:

<html>
<body>
<h1>Hello $name!</h1>
<p>Our products:
<ul>
#foreach($product in $products)
  <li>$product.name for $product.price
#end
</ul>
</body>
</html>

Here, the Java program must put variables name and products into the, so-called, page context before invoking the template. It is up to the Java program how does it calculate the values of those variables. Maybe it queries them from a database. But, the template author, who is perhaps not a programmer, need not care. He just displays the already prepared data in the HTML page, using the embedded Velocity directives. (The Velocity directives are resolved on the server side by the Velocity engine.)

Velocity is used not only with Web applications and HTML. It is a general-purpose text preprocessor. For example, you can use it as filter for whatever text files (say, java source code) with Ant task VPP.

Velocity homepage: http://jakarta.apache.org/velocity/index.html

An alternative to Velocity is FreeMarker (http://freemarker.sourceforge.net/).


Edit this page   More info...   Attach file...
This page last changed on 01-Oct-2003 23:25:37 BST by unknown.