Apache Tapestry

Apache Tapestry is an open- source framework for the programming language Java, can be created with the Web applications. It is not a stand-alone server, but runs in the context of a servlet container such as Tomcat web server. Tapestry is a top-level project of the Apache Software Foundation.

Tapestry applications consist of pages, one side of reusable and configurable components. Components in turn can be extended by so-called mixins.

In Tapestry, a page consists of two components: a XML template and a Java class ( java ). ( Tml. ). Within the XML template both HTML tags and specific Tapestry tags can be used for the dynamic content. This Tapestry tags are integrated over the specified element in the root namespace. The Java class is used for the processing of events such as clicking on a Tapestry - link or submitting a form.

The respective invoked methods can be set either through a preset naming scheme or an annotation. The two methods listed below would be so, for example, respond to the triggering of the link with the ID MyLink.

Void onActionFromMyLink () { ...}   @ OnEvent ( value = " action", component = " myLink " ) void myMethod () { ...} Its component-based architecture, the separation of presentation (HTML, XML) and Tapestry code conceptually similar to WebObjects, but are not compatible with this. Used together with Apache Cayenne, it is quite usable as a free WebObjects replacement, the change from one framework to another should go for experienced with one of the two frameworks developers due to the similarities smoothly.

Benefits

Tapestry is intended to simplify the development of Java web applications. The Framework has been designed so that it is easier possible to produce robust applications that in turn easier to install, debug and maintain than conventional servlet applications. It takes the developer from concerns about multithreading. The clear separation of HTML and Java application code and HTML developers can work together on a project. Tapestry also supports the internationalization of applications and the validation of user input and provides a set of pre-made GUI components such as calendars, sortable tables and trees. The functionality can be extended by creating your own components.

Another advantage of Tapestry is the fact that Java classes are usually simple POJOs to websites. It is therefore not necessary to inherit from superclasses or to implement prescribed interfaces. For this annotation can be used with which the inheritance is made ​​indirectly. Without foreign import project also Tapestry does not come out.

Rewinding (only to Tapestry 4.x)

In Tapestry up to version 4, the transmission of data through a form, takes place in three steps: In the first step, the HTML page is rendered with the form. The user edited in the second step, the input fields of the form, and finally starts the third phase by pressing the submit button.

The process has two request cycles. In the first cycle, the HTML page is requested and the form is rendered in this cycle. The second request cycle is initiated when you press the submit button.

In this cycle, Tapestry must perform the following actions:

  • The values ​​of the input fields are to be extracted
  • These values ​​are sometimes convert (String to Integer )
  • The converted values ​​are assigned to the correct Page / Component Video Properties

Since Tapestry in the assignment of the Properties to the input fields during the rendering, Tapestry uses an unusual approach: It determines precisely these relationships by the page is rendered again. This phase is also known as rewind phase.

In this phase, each component in the form in the same order is visited, as it happens in the initial rendering, and the actions described above are executed. In contrast to the initial rendering the listener method of the submit - form is called only in the Rewinding phase.

In Tapestry 5 of fragile Rewind mechanism was replaced by generated hidden fields, these now include the information necessary for the submit processing.

Examples

A simple Tapestry website

In the following, a simple Tapestry website is listed. Within this page, a global layout (t: layout ) will be used. This title has the parameter. To ensure the internationalization of the page, is not explicitly specified the desired title in the page description but a key for each translation file. Depending on the selected language, the variable $ {message is: title} now replaced by any text. This is set in the side associated properties file.

In addition, here is a simple Tapestry Page Link is used on the index page.

The real site About.tml

< t: layout title = "$ {message: title} "        xmlns: t = " http://tapestry.apache.org/schema/tapestry_5_1_0.xsd "        xmlns: p = " tapestry: parameter " >       

$ {message: text}        $ {message: index} < / t: page link> < / t: layout> The corresponding Java class looks like this:

Package org.examples.pages;   public class About {   } German Properties file:

Title: Sample Page text: This is a simple sample page index: Home English Properties file:

Title: my little example text: This is only a test index: Main Page Tapestry components

Multiple code used can be divided into individual components. These are usually made like an ordinary Web page from a Java class, a TML file and the corresponding translations.

The component listed here contains a parameter and creates for this link with the accompanying text.

     link to the page $ {target page} < / t: page link> < / t: container > The corresponding Java class:

Public class myPageLink {       @ Parameter ( DefaultPrefix = " literal" )     @ property     private String target page;   } Use of component:

Web Links

  • Official website
  • Free web framework
  • Java library
  • Apache project
72169
de