| | The Apache Velocity template engine simplifies creation of textual content by merging data contained in a Java object model with Velocity templates. But creating complex HTML tables with cells that span multiple columns and rows can lead to elaborate nested hierarchies of Velocity directives, which quickly render the Velocity template difficult to read and maintain. In this article Matthias Laux introduces a Java package that simplifies handling of even highly complex HTML tables, using a small number of directives while retaining all the benefits of Velocity for HTML generation. The package is independent of Apache Velocity and can potentially be used with other rendering schemes, such as JavaServer Pages. | In this article, I present a short primer on the Velocity Template Engine and its template language, Velocity Template Language (VTL). I also demonstrate how to use Velocity through several examples. | Template engines can be applied to a wide variety of development scenarios where you want to generate text based on specific processing rules, and are often used as the view component in MVC applications. In this article, Jeroen van Bergen explains where template engines fit into your application architecture and shows you some of the operations common to all template engines. Finally, he compares the two leading Java template engines, Velocity and FreeMarker, in terms of power, ease of use, and performance. | There are a variety of choices when it comes to producing dynamic web content. Typically, most projects will go with the accepted or de facto standards, so chances are, if the platform choice for your project is Java, you're likely to be using JSPs. This makes sense for a number of reasons: new staff are more likely to have experience with a standard; a number of web servers support JSPs, thus giving you a wide choice of web platforms; there is plenty of documentation available since people have usually "done it before"; and so on. However, sometimes using the standard isn't the best choice. Perhaps you need or want more direct control over the code producing your content; perhaps you have performance issues with JSPs; or maybe it's just that a new technical direction within your company is pushing away from that paradigm. Velocity is a simple, yet powerful, templating engine that can be used to generate dynamic content as an alternative to the incumbent standard. In some cases it provides a performance advantage over JSPs, and it certainly forces a web developer to think differently about separating content from code. | As described in part one of this series, code generation typically uses a template engine to transform some kind of "model" into compilable code, given the formatting specified by a template. In this second part of the series, I will show how to use Velocity inside of a code generator that is based on a well-defined Internal Object Model (IOM). You will see two different strategies: | Most of the real-world code generators, both commercial and open source releases, use templates and template engines. In this article I'm going to discuss template-based code generation, explain basic concepts related to templates and transformations, and demonstrate the huge benefits they can bring in code generation. Then, I'll implement a simple code generator in Java that uses Velocity, an open source template engine provided by Apache. The generator takes an XML representation of classes and data members and generates the Java code to define them. The generation process will be driven by a template that encapsulates the syntax of the target programming language. You will see how to change the template to generate different types of source code. | Most of the developers must be familiar with Velocity as a great open source template engine and I don?t think I need to say much about its uses and features as a template engine. This paper compiles its features as a rule engine. | | The introductory chapter looks at the concept of template engines, their specific uses and provides a whirlwind rundown on the basics of Velocity's feature set. Chapter 2 takes you through the basics of getting Velocity installed, writing some templates, and creating some output. Chapter 5 shows you how to build full applications with Velocity, both for the desktop and the Web. It focuses on building a simple e-mail newsletter app with Swing and Velocity. | Velocity is a fast and easy-to-use Java-based templating engine. Velocity's speed, ease of use, and flexibility contribute to its use in a broad range of applications, including code generation, email templating, and web user-interface creation. A template is a parameterized, predesigned text format. A template engine processes a template and fills in the parameterized pieces with concrete data. The bulk of this article focuses on email templating with Velocity. The template, in this context, is an email body with special syntax used to indicate points within the email to insert specific data, such as a name, order number, or order details. This article first introduces Velocity with a simple, easy-to-run example, then briefly covers the templating syntax, and ends with a full-featured and detailed look at Velocity in action for templating automated emails. | The last couple of days, I've managed to convert the MyUsers sample app from JSP to Velocity, and also to FreeMarker. Since this app uses SiteMesh, this was fairly easy thanks to its Velocity Decorator and FreeMarker Decorator support. Of course, Spring supports both technologies as well - ref: Spring+Velocity and Spring+FreeMarker. The real slick part of Spring's integration is that I didn't really need to change any code to support either templating engine. All I had to change was the XML in action-servlet.xml! Very cool! | The manipulation and transformation of textual data in standard presentation or exchange formats such as HTML and XML is a frequent and often tedious activity in which every software developer engages. A templating engine can facilitate this process by maintaining the static portion of the output in templates, while dynamically generating and positioning the changing portions. Velocity is a highly functional, open source templating engine that you can easily integrate into either client-side or server-side applications. | I'll use a familiar search use case to illustrate the Struts-Velocity integration recipe. In this example, a simple application lets a user search for a book by its ISBN number. The application's results page presents a book matching the ISBN number. | In it's simplest form, a template engine takes data, processes it and then displays it. For example, the data found in a company's employee list can be shown in a simple HTML page on the company's intranet or it can be simplied and seen on a salespersons' cellphone while he is on the road. The use of templates is what enables programmers and designers to interact and utilize the data in the most appropriate way. A very good example of what a template engine should be is Velocity. |
|