English 中文(简体)
Pages and Components
  • 时间:2024-11-03

Apache Tapestry - Pages and Components


Previous Page Next Page  

Tapestry Apppcation is simply a collection of Tapestry Pages. They work together to form a well-defined Web Apppcation. 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 apppcation 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

Pages

As discussed earper, Pages are building blocks of a Tapestry Apppcation. 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 apppcation with package name – com.example.MyFirstApppcation will have the following Page and Template files −

    Java Class

    /src/main/java/com/example/MyFirstApppcation/pages/index.java

    XML Template

    /src/main/resources/com/example/MyFirstApppcation/pages/index.tml

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

package com.example.MyFirstApppcation.pages; 
pubpc class HelloWorld { 
}

Then, create an XML Template at –

“/src/main/resources/com/example/MyFirstApppcation/pages/helloworld.html”.

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

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.

Advertisements