Apache Tapestry

from Wikipedia, the free encyclopedia
Apache Tapestry

Tapestry.png
Basic data

developer Apache Software Foundation
Publishing year 2000, February 11, 2013
Current  version 5.4.5
( September 6, 2019 )
operating system Platform independent
programming language Java
License Apache license
tapestry.apache.org

Apache Tapestry is an open source framework for the Java programming language that can be used to create web applications. It is not an independent server, but runs in the context of a servlet container such as the Tomcat web server . Tapestry has been a top-level project of the Apache Software Foundation since 2006 .

Tapestry applications are made up of pages, with one page made up of reusable and configurable components. Components, in turn, can be expanded using so-called mixins .

In Tapestry, a page consists of two parts: an XML template (.tml) and a Java class (.java). Within the XML template can both HTML - Tags are used and specific Tapestry tags for dynamic content. These tapestry tags are integrated via the namespace specified in the root element. The Java class is used to process events such as clicking on a Tapestry link or submitting a form.

The methods to be called can either be specified using a predefined naming scheme or using an annotation . The two methods listed below would react, for example, to the triggering of the link with the ID MyLink .

void onActionFromMyLink(){...}

@OnEvent(value="action", component="myLink")
void myMethod(){...}

With its component-based architecture, the separation of representation (HTML, XML ) and code, Tapestry is conceptually similar to WebObjects , without being compatible with it. Used together with Apache Cayenne , it can be used as a free WebObjects replacement. The change from one framework to the other should go smoothly for developers who are experienced with one of the two frameworks due to the similarities.

Special features

Live class reloading
Tapestry monitors all files in development mode and automatically accepts changes to pages, components, service implementations as well as HTML templates and properties files. This significantly increases the productivity of developers, since the application does not have to be restarted after every change.
Component-based
Individual pages can be built in Tapestry from small, reusable components. Each component has its own Java class and its own template. Tapestry can easily be expanded with your own components.
Convention over configuration
Instead of XML files, Tapestry uses naming conventions and annotation to configure an application.
Little use of the HttpSession
Tapestry largely refrains from using the HttpSession in order to be as efficient as possible in cluster operation.
Post / Redirect / Get
Forms in Tapestry follow the Post / Redirect / Get principle. This prevents users from accidentally submitting a form multiple times. In addition, the forward and back buttons in the browser work as usual and urls can be saved without any problems.
Inversion of Control (IOC)
Tapestry is based on its own Inversion of Control Framework, similar to Google Guice . However, it was developed with the aim of making all parts of an application replaceable and configurable, and it can also be used outside of web applications. Tapestry IoC can also be replaced by Spring IoC if necessary .

advantages

Tapestry is designed to simplify the development of Java web applications. The framework was designed to make it easier to build robust applications that are easier to install, debug, and maintain than traditional servlet applications. It relieves the developer of worries about multithreading . The clear separation of HTML and application code means that Java and HTML developers can work together on a project. Tapestry also supports the internationalization of applications as well as the validation of user input and offers a range of ready-made GUI components such as calendars, sortable tables and trees. The range of functions can be expanded by creating your own components.

Another advantage of Tapestry is the fact that Java classes for web pages are usually simple POJOs . So there is no need to inherit from superclasses or implement prescribed interfaces. Annotations are used for this, with which the inheritance is established indirectly. Tapestry cannot do without imports from outside the project.

Rewinding (only up to Tapestry 4.x)

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

The process results in two request cycles . The HTML page is requested in the first cycle and the form is rendered in this cycle. The second request cycle is triggered when the submit button is pressed.

During this cycle, Tapestry must do the following:

  • the values ​​from the input fields are to be extracted
  • these values ​​are sometimes to be converted (string to integer)
  • the converted values ​​must be assigned to the correct page / component properties

Since the properties are assigned to the input fields in Tapestry during rendering, Tapestry uses an unusual approach: It determines precisely these relationships by rendering the page again. This phase is also called the rewind phase .

In this phase, each component is visited in the same order as it is in the initial rendering and the actions described above are carried out. In contrast to the initial rendering process, the listener method of the submit form is only called in the rewinding phase.

In Tapestry 5, the fragile rewind mechanism was replaced by generated hidden fields, which now contain the information necessary for submit processing.

Examples

A simple Tapestry website

Below is a simple Tapestry website. A global layout (t: layout) is used within this page. This has the parameter title . In order to ensure the internationalization of the page, the desired title is not explicitly specified in the page description, but a key for the respective translation file. Depending on the language selected, the $ {message: title} variable will now be replaced by any text. This is specified in the properties file belonging to the page .

In addition, a simple tapestry pagelink is used on the index page.

The actual About.tml website

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

    <p>${message:text}</p>

    <t:pagelink page="index">${message:index}</t:pagelink>
</t:layout>

The associated Java class looks like this:

package org.examples.pages;

public class About{

}

German properties file:

title: Beispielseite
text: Dies ist eine einfache Beispielseite
index: Hauptseite

English properties file:

title: my little example
text: This is only a test
index: Mainpage

Tapestry components

Code that is used more than once can be separated into individual components. These usually consist of a Java class, a TML file and the associated translations, just like a normal website.

The component listed here contains a parameter and creates a link with associated text for it.

<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
    <t:pagelink page=${targetPage}>Link auf die Seite ${targetPage}</t:pagelink>
</t:container>

The associated Java class:

public class myPageLink{

   @Parameter(defaultPrefix = "literal")
   @Property
   private String targetPage;

}

Use of the component:

<t:myPageLink targetPage="index"/>

Web links

Individual evidence

  1. books.google.at .
  2. a b projects.apache.org . (accessed on April 8, 2020).
  3. tapestry.apache.org .
  4. tapestryjava.blogspot.de
  5. tapestry.apache.org
  6. Drobiazko, 2012, p. 20
  7. a b Drobiazko, 2012, p. 7
  8. tapestry.apache.org
  9. tapestry.apache.org
  10. tapestry.apache.org