Introduction to the Tapestry Web Framework
This document takes you through the basics of using the
Tapestry Web Framework
in NetBeans IDE.
At the end of this tutorial, you will have a simple Tapestry
application, exactly as provided by the official Tapestry Quick Start Tutorial:
Throughout this tutorial, we will make use of the Tapestry Support Module for NetBeans IDE, created
and maintained by Andreas Andreou, in Athens, Greece.
The following topics are covered below:
This tutorial can be completed in 20 minutes.
For more information on Tapestry. For details on
support for Tapestry in NetBeans IDE. If you
are familiar with Tapestry, you are welcome to contribute code to the Tapestry Support module
for NetBeans IDE.
Setting Up the Environment
Before you start writing your Tapestry application, you have to make sure you have all of the necessary software
and that your project is set up correctly. Once you have installed
the Tapestry Support module for NetBeans IDE, you will have a wizard that sets up all the basic files
needed for a Tapestry application.
Installing the Software
Before you begin, you need to install the following software on your
Note: You do not need to download the Tapestry JARs from the Tapestry site
before beginning this quick start,
unless you want to do so. If you do not download the Tapestry JARs separately, you
will be prompted to do so by the Tapestry Support Module, within the wizard that sets
up the project sources, as you will see later in this quick start.
Creating the Source Structure of a Tapestry Application
The source structure of our application must include the Tapestry JAR files,
the registration of the Tapestry servlet in the web.xml file, as
well as some standard artifacts such as the home page.
Since we are using an IDE, we shouldn't need to create all these files by hand.
Instead, we have a wizard to do the work for us. Specifically, the final
panel of the Web Application wizard will be very useful in the context of
our Tapestry application.
- Choose File > New Project. Under Categories, select Web. Under
Projects, select Web Application. Click Next.
- In the Name and Location panel, type DemoTapestryApplication in Project Name.
Project Location to any directory on your computer.
- Leave all the other settings unchanged. Or, if you like, you can change them.
Tapestry supports J2EE 1.4 as well as Java EE 5. A Tapestry application can be deployed
to any server. Click Next.
- In the Frameworks panel, choose Tapestry. You will be given an opportunity to browse
to the top level of your Tapestry download or select a
registered Tapestry library:
If you click the "Download Bundle" link, shown in the screenshot above, the Tapestry Support Module
for NetBeans IDE page will open in the IDE's default browser. From there, you can download all the JARs
in one go.
Once you have selected an appropriate folder containing the Tapestry JAR files,
use the Options tab to set the following:
- Tapestry Servlet Name. Specifies the name of the servlet in the web.xml file.
- Tapestry URL Pattern. Adds the relative URL pattern to the web.xml file.
- Main Package. The Java package in which you can create your Java source files.
- Enable Friendly URLS. Friendly URLS concern themselves with two issues:
- Converting information normally stored as a query parameter into part of the URL path.
- Parsing the path to restore the information previously encoded.
For example, the 'ugly' URL /app?page=news/Thread&service;=page may
be converted into the friendly URL /news/Threads.html. In this case,
the page=news/Thread query parameter became
the news/Thread portion of the URL, and the service=page query
parameter became the .html extension to the URL.
For this tutorial, you can keep all the defaults in the Options tab. Click Finish.
The IDE creates the DemoTapestryApplication
project. The project contains all of your sources and
project metadata, such as the project's Ant build script. The project
opens in the IDE. You can view its logical structure in the Projects window (Ctrl-1).
Make sure that all the following JAR files are available, when you expand
the Libraries node. If they are not there, manually add them by right-clicking the Libraries node,
choosing Add JAR/Folder, and browsing to the JARs in your filesystem. Before going
further, your Libraries node should contain the following JAR files:
Next, note that the following Tapestry artifacts have been created for you:
Without any programming whatsoever, you can already run your application.
Right-click the project node and choose Run Project. The server starts, if it
is not running already, and the application is deployed. The IDE's default browser
starts up, showing you the following overview page:
Implementing the Tapestry Quick Start
In this section, we refer to the Tapestry Quick Start Tutorial
and show how easily and smoothly you can implement it in NetBeans IDE.
- Open Home.html and replace the content with the following tags:
- Open the web.xml and notice that, unlike in the Tapestry Quick Start Tutorial,
there is nothing you need to do here, because the New Project wizard has done all the work for you.
- As in the quick start, add the following tags between the BODY tags in the home.html
The current data and time is:
<strong><span jwcid="@Insert" value="ognl:new java.util.Date()">June 26</span></strong>
- Finally, add the following tags, to create a new link for refreshing the page:
<a href="#" jwcid="@PageLink" page="Home">refresh</a>
- Run the application. In the Overview Page, click Start Application.
You should now see the following:
This is the end of the introduction to web development using Tapestry
in NetBeans IDE. Note that the Tapestry Support Module offers a lot more
functionality than is described here.
You are encouraged to continue your journey in the Tapestry
framework by working through other tutorials described on
the Tapestry Home Page.