Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Introduction to Tapestry: An Object Oriented Open Source Java Based Framework

In this article we will explore all the settings and important features of Tapestry Framework, a Java Based Framework for web development.

The commonly used Java/open source based web frameworks e.g. Struts, PHP, servlets, etc. are known to be operation-centric. We create the Action classes also known as servlets, or any other similar components which are invoked when the user clicks a link or submits a form. In this case we as developers are responsible for selecting the appropriate URL, name and type of the query parameters, so that we can pass them along with the URL.

Not only that we are also responsible to connect our output pages, no matter it is JSP, Velocity templates, or any other format available in the template technology. It is required to construct these URLs and use them either within the href attribute of the tag, or in the action attribute of the tag.

Things are different inside the Tapestry framework. A tapestry based application contains pages. All these pages are created using small components. Components may again be constructed from other smaller components. Each and every page is given a unique name and within a page every individual component has own unique id. This model is known as the component object model. In tapestry, effectively every component has a unique address which can easily be integrated into a URL.

Practically we don't need to write a servlet for a typical shopping cart 'add-item' operation. Fact of the matter is that, we don’t even write a component for this kind of operation. What we need to do in this situation is, we take an existing component, for e.g. Direct Link, and start configuring it. When the component is rendered, it creates a callback URL. When we click on that link, the callback URL includes the name of the page and the id of the component within the page. This will invoke a method on the component and the method invokes the application specific listener method.

Tapestry is a component-based web application framework, in Java. Tapestry is not just a simple template system. It is built on top of the Java Servlet API and creates a platform which helps in creating web sites which are dynamic as well as interactive. Tapestry is not just another template language, but also it is a real framework used for building complex applications using simple, reusable components. Tapestry has the ability to offload much of the error-prone work while it creates the web applications within the framework itself. It takes over the tasks which are important, for e.g. Construct and interpret the URLs which are encoded with certain information and dispatching the incoming requests. Also it can handle the localization and internationalization in a much efficient way.

The core concept of Tapestry is based on components like objects, methods and properties. Which means that rather than it has the developers concerned about the perimeters of the Servlet API e.g. requests, responses, attributes, parameters, URLs, sessions and so on, it allows the developers to focus on the objects which not only includes the Tapestry pages and components, but also has the domain objects of the application. Thus, in a Tapestry based application, user actions e.g. submitting the forms or clicking the links leads to a change in the object properties along with the invocation of user-supplied methods. This includes the business logic as well. The Tapestry framework takes care of the plumbing which is required to connect the user actions with these objects.

This concept can take some time before we get used to it. Here we don't write the servlets rather we write the listener methods. We don't construct the URLs to the servlets either. We make use of an existing component e.g. Directlink and then configure its listener parameters in order to invoke our listener method. The listener method simply interacts with the middle ware systems which is usually a stateless session EJB or even does some other bookkeeping tasks which are related to the request and then selects a new page in order to provide a response to the user. Using this framework, we write much lesser code as compared to the standard servlet based frameworks since the mechanical tasks of creating the URLs, dispatches the incoming requests, manages the server-side state and so on becomes the responsibility of the framework. I don't mean here that the Servlet API is inaccessible from this framework; it is simply irrelevant for a typical Tapestry user.

This document describes most of the internals of Tapestry. This should not be treated as a tutorial. This document is more of a guide to internals of Tapestry which is intended to help experienced developers who desire to rely completely on the Tapestry framework.

The current version of Tapestry is release 4.0. The main focus of Tapestry is to generate dynamic HTML pages. Although we have lot of support for XHTML, WML and other types of markup languages as well.

Nearly all of the Tapestry based API is described in terms of interfaces with default implementations supplied. Substituting the new objects using the appropriate interfaces, the behavior of the framework can be changed considerably, for example overriding the pages and other component specifications that are stored may be in a database.

Internals of Tapestry

The best part of the Tapestry framework is the fact that this framework is component based and not operation based. Major web technologies e.g. Struts, servlets, PHP, etc. all are operation based frameworks wherein we create the servlets or Action classes, or any other similar controllers, which are invoked when the user clicks on a link or hits the submit button of a form. We as developers are responsible to select the appropriate URL, the name and type of the query parameters, if any. We pass these query parameters along with the information which is required in the URL.

While using the operation based framework, we are also responsible to connect our output pages which can be either Velocity templates, JSPs, or any other different formats available in the template technology which are capable of handling these kinds of operations. This requires us to construct these URLs and add them in the action attribute of the tag or in the href attribute of the tag.

Things are quite different while we talk about Tapestry. Tapestry based web applications consist of pages. These pages are built using small components. These components may themselves be formed using other components. Each and every component within a page will have its own unique id also every page here holds a unique name. That is why it is called component object model. As a matter of fact, each and every component has an address which can be easily be incorporated into a URL.

In Tapestry, we take an existing component, e.g. a Direct Link, and then configure it. When the said component is rendered, it creates a callback URL. When we click on that link, the callback URL that includes the unique name of the page and the corresponding unique id of the component which is within the page will invoke the method on the component. This method then invokes the application-specific listener method. Refer to the following diagram which explains the workflow of the tapestry framework.

Figure 1: Tapestry work flow diagram

Advantages of Tapestry

  • Pure Java based - The entire 'Tapestry' is developed using Java. No reflection, simple design. Designed and developed to support multithreading. We can write our pages or components using Java, Groovy, Scala or any other similar language.
  • Easy configuration - We can say good bye to the XML based configuration. Here we use the dependency injection concept and annotation based configuration.
  • High productivity - We can change the classes on the fly. Thus fixing any issue is much faster.
  • Scalable - Very easy and convenient mechanism to scale up and add additional servers.
  • Advanced Exception Management - Exceptions are properly managed. Provides enough information which is helpful to debug any problem.
  • Testability - Built in features to support Test Driven Development.

Tapestry Components

Tapestry splits a web application into multiple sets of pages. Each page is assembled using the Tapestry components. These components themselves may again be made up of several other components. There is no defined depth limit. The Tapestry pages are also components. But these components have some additional responsibilities.

All the Tapestry components are the containers of some or other components. These Tapestry pages and the most of the components which are user-defined, come with their own template. This template is nothing but an HTML file which defines the static parts as well as the dynamic parts of the component, along with the markers. These markers are to indicate the location where embedded components should be active. It is not mandatory for every Component to have a template; most of these components which come with Tapestry generate their own portion of response within the code, not using any template.

These Components may also have one or multiple named parameters which are bound by the page or component which it belongs to. Unlike the usual Java method parameters, Tapestry component parameters can be bidirectional means to say that a component may read a parameter to fetch a certain value, or use the same parameter to set a value.

Most of the components are limited only up to generating the HTML. A certain part of the components deals with the other side of the requests. Which means it is used to handle the incoming requests. API Link classes, e.g. Page Link, Direct Link etc. are used to create the clickable links that are rendered on the page. These links are also involved in dispatching the user developed code when any such link is clicked.

Other components e.g. Form, form control components such as Text Field, Drop down lists, Checkbox, Radio selection items etc., facilitate the HTML forms. When these components are rendered, they also read the properties from the application objects in order to provide the default values. When these forms are submitted, the components which are within the form read the HTTP query parameters convert the values into appropriate types and then update the corresponding properties of the application objects.

Tapestry Engines and Services

Tapestry framework has evolved a lot over the period of time.

The Engine is the central object and has the same importance in the Tapestry framework which the HttpSession has in the Servlet based API. This Engine stores the persistent state of the application e.g. the properties which exist from one request to the next or from one page to the other. This job is done by storing the Engine itself into the HttpSession. In this document, we will mainly talk about the default implementation. On top of this we will provide few notes on how this default implementation may be extended or overridden, where appropriate.

The Engine services acts as the bridge between the servlets and the URLs and the rest of Tapestry framework. The services are responsible for the following:

  • URL encoding
  • Providing the query parameters to the framework which identifies the exact operation which needs to take place when the generated URL is triggered. This trigger is caused when the end user clicks on a link or submits a form.
  • Dispatching the incoming requests.

This encapsulation mechanism of the URL encoding and decoding within a single object is the main factor on how the Tapestry components can operate without being concerned on how they are designed and on which page. These pages are considered by the services while formulating the URLs.

The 'Visit object' is an application based object which acts as a focal point for all server side components which are not associated with a single page. Individual applications define the class of the Visit object. This Visit object is stored as a property of the Engine, and eventually this is persisted in the HttpSession Object.

The 'Global object' is also an application based object. These store the information which is global to the entire application and are independent of any particular user or session. A common example for the Global object is the central logic which performs the JNDI lookup of session EJBs.

Tapestry and Object Graph Navigation Language or OGNL

Tapestry is tightly coupled with OGNL or the Object Graph Navigation Language. OGNL is a Java based expression language which has the ability to peep into the objects and can read or can even update their existing properties. OGNL is quite similar to, and at the same time, it is much more powerful than the expression language which is built into the JSP 2.0 based standard tag library. This language not only supports the property access, it can also include the mathematical expressions and method invocations. It can refer the static fields of the public classes. Also it can create new instances of the objects, which includes lists and maps.

The simplest OGNL expressions are the property names, e.g. empName which is equivalent to the methods getEmpName() or setEmpName if it is being used to update the 'empName' property. The "Navigation" part of this language comes into picture when the expression has a of property names, such as empName.firstName, which is equivalent to getEmpName().getFirstName(). It can go upto any level. While using these expressions we should be very careful and ensure that the intermediate property empName, in this case is not null.

OGNL has the ability to allow multiple objects e.g. a page and a component which contained within that page. It can share the information among these objects.

How Tapestry works

Tapestry uses a different model which is well structured, has organized pages, and has components within these pages. Everything in Tapestry has a very specific name which we need to provide. Once we get to know the page name, we also know the location of the Java class which is responsible for this page, the location of the template for this page, and also the entire structure of the page. Once of these information is provided to Tapestry, it can make the things just work.

Tapestry allows us to develop the code in terms with our choice. We can freely use the Java annotations in order to use the objects. If we have the information how to store, we can store them as fields of our classes, and not inside the HttpServletRequest or HttpSession. If we need to execute some code, we can take the help of simple annotation or the method naming convention in order to get Tapestry invoke that method, at the right time, with the appropriate data. The best part is that these methods don't even have to be public.

Tapestry has the ability to handle most of the multi-threaded aspects of web application development. It can manage the life cycle of our page and the component objects, and also the fields of the pages and the components, in a thread safe manner. The page and component classes’ looks like simple and standard POJOs.

Tapestry - Past and Future

Ever since its inception in way back early 2000, Tapestry going through a constant process of enhancements which are driven by feedback received from its community. Tapestry underwent a big change in 2003 when the entire project shifted from Source Forge to Jakarta. This transaction caused the change in release version from 2.3 to release version 3.0 sometime in April 2004.

Tapestry 3.0 was mainly designed in order to change the approach of how the Tapestry applications are created. This version introduced some sort of Rapid Application Development or RAD support in the form of implicit components. Implicit components are nothing but a manner of specifying the component's type and the parameters which are being used in the HTML template. This html template is known to be much more familiar to the developers from the JSP and PHP community.

Tapestry 3.0 also introduced the line based error reporting technique in which the runtime errors get related back to relevant lines in the HTML template or in the specification file. The 3.0 version also introduced the element, and the byte code enhancement technology along with it.

Tapestry version 4.0 is even more enhanced over version 3.0. This version has introduced a new, sophisticated infrastructure along with the Hive Mind microkernel. The new backbone provides the required support to cater the needs of Tapestry's bigger community which includes the support pre-formatted URLs, integration with the Java Portlet API, and modularization of applications which allows the use of folders, and thus the J2EE based security mechanism. In addition to this a more sophisticated approach of implementing the linked parameter properties is added in release 4.0. In addition to these, the version 4.0 adds up more flexibility to storing session-specific state e.g. HTTP query parameters. For the JDK 1.5 users, the complicated XML page and the component specifications can now be replaced with Java annotations.

Start the work

In order to start working with Tapestry, we need to have the following -

  • JDK 1.5 or higher - Tapestry version 4.0 requires JDK 1.5 or higher. But the Version 5.4 requires JDK 1.6.
  • Eclipse IDE - Eclipse has been widely accepted as an IDE for the Java world and Tapestry is not an exception to this.
  • Apache Maven - Apache Maven is also widely used as a build tool along with ANT. Tapestry framework relies heavily on the Apache base Maven tool in order to build the war or the jar files.
  • Jetty or Tomcat - Either one of these two application servers is required to as a web container or a servlet container.

Tapestry principles.

The entire tapestry framework is based upon the following principles -

  • Static Structure but Dynamic Behavior - Tapestry framework follows more or less a static structure but it comes up with a Dynamic Behavior. For e.g. -
    • Agility
    • Scalability
  • Adaptive API - The key feature of Tapestry is that the API is very much adaptive. The traditional frameworks e.g. struts, JSF requires a good amount of development before it can be used.
  • Backward Compatibility - This framework ensures the backward compatibility to ensure that the developed applications do not break all of a sudden. To achieve this, Tapestry 5 can go thru an internal change without impacting any of the any of the application code we develop. This version has finally cracked the backward compatibility issue. This doesn’t allow us to have a great assurance which we can upgrade to the future releases of Tapestry without breaking the existing applications.

Conclusion

In this article I have given a small introduction of the Tapestry frame work. Also discussed is how the framework is organized and how it works. Let us now conclude our discussion in the form of following bullets -

  • Tapestry is more than a simple template system. It is a component-based web application framework, written in Java.
  • Tapestry can handle the localization and internationalization in a much efficient way.
  • This framework is component based and not event based which helps in faster development.
  • Tapestry comes with the following advantages -
    • Pure Java based - The framework 'Tapestry' is developed using Java.
    • Easy configuration - In tapestry we have annotation based configuration.
    • High productivity - We can change the classes on the fly. Thus fixing any issue is much faster.
    • Scalable - Very easy and convenient mechanism to scale up and add additional servers.
    • Advanced Exception Management - Exceptions are properly managed.
    • Testability - Built in features to support Test Driven Development.
  • These Tapestry pages and the most of the components which are user-defined, come with their own template. This template is nothing but an HTML file which defines the static parts as well as the dynamic parts of the component, along with the markers.
  • The Engine services acts as the bridge between the servlets and the URLs and the rest of Tapestry framework. The services are responsible for the following:
    • URL encoding
    • Providing the query parameters to the framework which identifies the exact operation which needs to take place when the generated URL is triggered. This trigger is caused when the end user clicks on a link or submits a form.
    • Dispatching the incoming requests.
  • Tapestry is tightly coupled with OGNL or the Object Graph Navigation Language. OGNL is nothing but a Java based expression language which has the ability to pierce into the objects and can read or can even update their existing properties.
  • Ever since its inception in 2000, Tapestry has gone through many changes and evolutions.
  • In order to work with the Tapestry framework, the following software are required -
    • Java 1.5 or higher
    • Eclipse IDE
    • Apache Maven
    • Tomcat or Jetty web server
  • The Tapestry framework is based on the following principles -
    • Static structure, dynamic behavior
    • Simple API
    • Backward compatibility

I hope this document will give you a brief idea about the Tapestry framework and its features. Happy reading!



Website: www.techalpine.com Have 16 years of experience as a technical architect and software consultant in enterprise application and product development. Have interest in new technology and innovation area along with technical...

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login