Skip to main content

Templating with Velocity

Posted by daniel on February 18, 2004 at 7:32 AM PST

"For server-side applications, when integrated with Web tier containers compatible with Servlet 2.3+, Velocity provides a viable alternative to JSP technology that can enforce a clean separation of presentation logic from application business logic."

We link to Sing Li's developerWorks article on the Velocity Template engine in
Also in Java Today
. He begins with a standard mail merge type of example noting that such an "application is most useful when the data source being merged is large and varied." In many cases, the need just isn't great enough to take the step of creating a template for simple tasks. But, as you also saw in Erik Hatcher's article Velocity: Fast Track to Templating , what makes Velocity so powerful is that you can go from 0 to 60 pretty quickly.

Use of #if, #then, #else, and #foreach allows you to easily add selective rendering and repetition. So called velocimacros "enable you to encapsulate template scripts and reuse them easily." To import Java objects so that Velocity templates can access them you use the org.apache.velocity.context.Context.

Li concludes his article by comparing the use of Velocity on the server side with JSPs and shows you how to deploy Velocity with Tomcat 5. He cautions that "the JSP model provides unhindered access to the underlying Servlet API and Java programming language. In fact, to avoid access to these native features, you will have to exercise great discipline in coding (using only EL, tag libraries, and the like). Essentially, this is a wide-open access model." He continues that Velocity's "closed model allows Velocity to provide a decoupled templating presentation layer, cleanly separated from any application business logic or data management code."

Our other linked article is an overview of the new features you
now have access to in the J2SE 1.5 beta. In this Oracle Technology Network article, Jason Hunter previews the Big changes in J2SE 1.5. Written well before the current release, Jason describes Generics, covariant return types, autoboxing, enhanced for loop, varargs, static imports, and type safe enums. Also in today's Weblogs John Mitchell points to Gilad Bracha's Generics Tutorial.

In today's Projects and Communities The Java Communications homepage announces that JSR-22, the JAIN Service Logic Execution Environment API Specification has gone final.

People have started to publish tutorials in the Education and Research community. You can start with the Java Advanced Imaging examples and tutorial.

In today's News Headlines

Registered users can submit news items for the href=""> News Page using
our news submission
. All submissions go through an editorial review by news director
Steve Mallet before being posted to the site. You can also subscribe to
News RSS feed

Current and upcoming
Java Events