JVM Version 1. 0 JVM Vendor Sun Microsystems Inc. JVM Implementation Version 1.
Velocity Template Language(VTL) .
Complex HTML tables made easy with Apache Velocity. 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 Java. Server Pages. I've worked on several projects that required generated HTML pages to display large amounts of data, typically available in a database or as XML files.
To apply the well- established Model- View- Controller paradigm, I used Apache Velocity as the template engine to generate all the pages. The controller application's task was to read the data, fill in some Java data structures based on the data model for a given use case, and merge the data objects with Velocity templates.
Most of the data I worked with required extensive use of HTML tables on the Velocity side. The data contained hierarchical information, so the tables became increasingly complex because cells had to be merged using rowspan or colspan attributes to reflect the hierarchies. Correct output of required HTML markup elements such as < tr> and < td> , and the use of rowspan and colspan attributes, had to be controlled by Velocity directives (such as #if .. This recurring pattern led me to implement a general solution for handling complex tables in this context.
Beyond basic functionality, I wanted the solution to include some convenience features, such as: The ability to grow a table dynamically after instantiation. Flexible behavior at the boundaries: clipping and autogrowth during cell insertion. Compacting of tables. Cloning of tables. This article introduces my solution: a Java package that takes the complexity out of HTML table generation with Velocity. First I'll demonstrate how complex tables lead to overly complex Velocity templates.
Then I'll show you how you can use my solution to generate a complex table with minimal Java code and a few Velocity directives. Finally, with the help of a real- world example, you'll learn how to take advantage of the package's convenience features.
Table 1 is an (abridged) example of a fairly complex table. Several of its cells are combined via rowspan attributes. Main. Topic #Topic #Sub. Topic #DOC3. 1Developer Guide. Fact Sheet. 4General. How. To. 1Module Whitepaper.
Tutorial. 1General. Concept Paper. 2IDN1. Release Documentation.
User Guide. 1Training Material. HF Conference. 7INF2. Deployment Infrastructure. Performance. 1Development Environment. Generator. 12. Test Infrastructure. Audit. 1Authentication.
Introduction: Velocity is a Java-based template engine, a simple and powerful development tool that allows you to easily create and render documents that format and present your data. In this guide, we hope to give an overview.
Document. 1Test Client. User Management. 1Tools for e. HF Users. 1Security Workbench.
Total Count. 59 Total Count. Total Count. 59. Table 1. A fairly complex table. The values of the rowspan attributes in Table 1 must be assigned dynamically at page- creation time, because the number of hierarchy elements (Main.
Topic, Topic, and Sub. Topic), and the string values, aren't known until then. For this reason, the Velocity template must handle the required HTML output, causing the template to be cluttered with directives to handle all possible cases. As you can see in Listing 1, the template contains several references to the data model objects (such as $category. Data). Listing 1. Portion of the Velocity template for Table 1< table cellpadding=.