Apache Tapestry - Pages and Components

Tapestry Application is simply a collection of Tapestry Pages. They work together to form a well-defined Web Application. Each Page will have a corresponding XML Template and Zero, one or more Components. The Page and Component are same except that the Page is a root component and usually created by an application developer.

Components are children of the root Pagecomponent. Tapestry have lots of built-in components and has the option to create a custom component.

Page Component


As discussed earlier, Pages are building blocks of a Tapestry Application. Pages are plain POJOs, placed under – /src/main/java/«package_path»/pages/ folder. Every Page will have a corresponding XML Template and its default location is – /src/main/resources/«package_name»/pages/.

You can see here that the path structure is similar for Page and Template except that the template is in the Resource Folder.

For example, a user registration page in a Tapestry application with package name – com.example.MyFirstApplication will have the following Page and Template files −

  • Java Class


  • XML Template


Let us create a simple Hello World page. First, we need to create a Java Class at – /src/main/java/com/example/MyFirstApplication/pages/HelloWorld.java”.

package com.example.MyFirstApplication.pages; 
public class HelloWorld { 

Then, create an XML Template at –


<html xmlns:t = "http://tapestry.apache.org/schema/tapestry_5_4.xsd"> 
      <title>Hello World Page</title> 
      <h1>Hello World</h1> 

Now, this page can be accessed at https://localhost:8080/myapp/helloworld. This is a simple tapestry page. Tapestry offers lot more features to develop dynamic web pages, which we will discuss in the following chapters.