Templating with Velocity
"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 java.net News Headlines :
- Simon Phipps Answers Eric Raymond's Open Letter to Sun
- Microsoft, Intel Forge New Web Services Spec
- Jakarta Slide 2.0 Beta1
- OpenReports Designer 1.0.0
- JORAM 4.0
- CGLIB 2.0 Final
Registered users can submit news items for the java.net News Page using our news submission form. All submissions go through an editorial review by news director Steve Mallet before being posted to the site. You can also subscribe to thejava.net News RSS feed.
Current and upcoming Java Events :
- February 17-18 Sun Tech Days
- February 18 Washington DC Linux User Group: Using Open Source Java Web Application Frameworks
- February 19 JXTA BOF associated with Java Technical Conference
- February 20-22 CodeCon 2004
- February 20-22 Java Freedom Software Symposium
- February 24-26 Edge 2004 East
- March 22-26 Game Developers Conference, 2004
Registered users can submit event listings for the java.net Events Page using our events submission form. All submissions go through an editorial review before being posted to the site.
Archives and Subscriptions: This blog is delivered weekdays as the Java Today RSS feed. All java.net members can subscribe to the email updates for the site at the java-net Mailing Lists page. You must be logged in to subscribe to the javanet_Daily and javanet_Weekly lists. Also, once this page is no longer featured as the front page of java.net it will be archived along with other past issues in the java.net Archive.
- Login or register to post comments
- Printer-friendly version
- daniel's blog
- 378 reads





