ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Tapestry: A Component-Centric Framework

by Hemangini Kappla

Tapestry is an open source web application framework written in Java. Highly-interactive and content-rich applications can be easily developed using this framework.

Tapestry offers advantages including a high-performance coarse-grained pooling strategy, high code-reuse, line-precise error reporting, and lots more. Tapestry applications can be run on any servlet container since the apps are 100 percent container agnostic.

Adoption of the tapestry framework eliminates writing servlets and building URLs and query parameters to servlets, even though Tapestry is built on top of the servlet API. Developers can concentrate on coding the application's functionality because Tapestry takes care of the "plumbing" code (creating URLs, dispatching incoming requests, managing server-side state, and so forth).

The Tapestry Distribution

The Tapestry distribution is available for download at the Tapestry home page on the Apache site.

The Tapestry distribution consists of the following pieces, illustrated in Figure 1:

  • The main Tapestry framework: This archive consists of all the core components of the Tapestry framework. It also contains other classes that are used to provide services to pages and components.
  • Contributed components: This is a collection of powerful add-on components for Tapestry contributed by the community. It has components that are used to create the HTML response for rendering the pages. These components can be used in applications, to incorporate logic constructs in HTML templates.
  • Annotation support classes: This library contains annotations. These annotations require JDK 1.5 to run. Annotations are modifiers that could be added to the code. One can perform some operations inside Java code that otherwise would be specified in the page or component specification.
  • Portlet support: An add-on module for Tapestry that enables the use of Tapestry to create JSR-168 portlets.

Contents of the Tapestry distribution
Figure 1. Contents of the Tapestry distribution

Tapestry has a number of additional runtime dependencies, which must be downloaded and packaged with the above JAR files in the WEB-INF/lib folder of Tapestry web applications. This can be done by the Ant build scripts for Tapestry, which will automatically download these dependencies. The build scripts require some configuration to work; details are available at the Tapestry Wiki. Alternatively, these dependencies may be downloaded from Howard Lewis Ship's quick-start directory as tapestry-libraries.tar.gz (21.7 MB). Copy the dependencies to the WEB-INF/lib folder or any shared library folder to make the JAR files available to the application that is to be developed based on the Tapestry framework. Since Tapestry is a library, this is all that needs to be done for the installation part.

The Component World of Tapestry

A Tapestry application is different from other traditional web applications based on operation-centric frameworks (e.g., Struts, PHP, etc.). A Tapestry application is a collection of web pages, and each web page is in turn constituted of components. The web pages in Tapestry are nothing but simple HTML pages (not JSPs) and are called as HTML templates. The entire web application is built from these templates and specifications, using minimal Java code.

The Tapestry framework acts as a layer between the Tapestry application and the Java Servlet Container. Tapestry uses the standard Servlet API objects and functions within the existing Servlet container. Since the application components access the Tapestry components, the developed application is totally oblivious of the Servlet API.

In Tapestry-based applications, all the elements on a web page (forms, links, test-boxes, etc.) are represented as components. At the heart of the design is the interface org.apache.tapestry.IComponent. All objects that may be used to provide dynamic content on a Tapestry-based page are represented by this class.

Figure 2 shows some of the classes and their relations. In short, everything from forms, components of forms like text areas, text fields, hidden fields, submit buttons, and links are represented as objects, methods and properties (each component having its own id). This is the unique Component Object Model (COM).

Thumbnail, click for full-size image.
Figure 2. Class diagram showing the relation between Tapestry components (Click for full-size image)

Pages: 1, 2

Next Pagearrow