How To Quickly Develop Java Programs With Tapestry
As you work with J2EE, you will find that there are a large number of programs which have been designed to make it easier to work with. If you are a programmer, the last thing you should want to concern yourself with is basic low level programming work.
If you are like many programmers, you probably want do deal with issues that are related to business. One example of a program that can help you is called the Model View Controller, or MVC. There are a number of other useful frameworks such as JavaServer Faces, which is popularized by Sun.
Another program which has gathered a lot of attention is called Tapestry. Tapestry is an open-sourced program which is designed to work with programmers who want to create object oriented Java applications. Programmers who use Tapestry will be able to store data with object properties, and they will also be able to work with user actions and event handling. Another feature that you will find impressive about Tapestry is the HTML templates. Each page in Tapestry will have an HTML tag which is designed for browsers. It is much easier to use than JSTL or JSP.
Tapestry is built with a basic Servlet API. This means it can run on any Java program server. Before you begin, you will need to create the Tapestery servlet on the web.xml file. Below is the code that will help you accomplish this:
< ?xml version="1.0" encoding="UTF-8"? >
< !DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
< web-app >
< display-name > Introduction to Tapestry Tutorial< /display-name >
< servlet >
< servlet-name > app< /servlet-name >
< servlet-class >org.apache.tapestry.ApplicationServlet< /servlet-class >
< load-on-startup >0< /load-on-startup >
< /servlet >
< servlet-mapping >
< servlet-name >app< /servlet-name >
< url-pattern >/app< /url-pattern >
< /servlet-mapping >
< /web-app >
You can pick any name you want to use for the servlet. At the same time, changing the URL is a bit more complex. Because of this, it is best to leave it alone unless you have some experience dealing with this issue. To fully understand how Tapestry can help you create Java programs, it is first important to list an example. I will go over a basic tutorial of the Tapestry interface. In this example you will be using a website which sells cheap plane tickets. Your discount offers will be represented by the TravelOffer class.
The TravelOffer class will provide information about the city that you are traveling to, as well as the price. The FeatureOffer class will give information about the business methods for various discounts. The FeatureOfferImpl class will deal with the creation of the interface. You will now want to create the very first page of Tapestry. Each Tapestry program will have a homepage called Home. The homepage you see will have a limited amount of information.
However, there are two important things it will need to have, and these are the page template and the Java class which is connected to it. The page template will have a combination of HTML code and Tapestry elements which are dynamic. The Java class will show information about the dynamic elements of the page. If you are using Tapestry 3, the pages will need to have specification files. These files will be XML types, and they will give a description of the mapping between the Java class and page template. If you are doing something basic, they are not necessary. The page template that you will be working with should look something like this:
< html >
< head >
< title >Tutorial: Introduction to Tapestry< /title >
< /head >
< body >
< h3 >Online Travel Discounts< /h3 >
< h4 >One of today’s feature destinations:< /h4 >
< p >
A trip to
< span jwcid="@Insert" value="ognl:featureDestination.destination" >Paris< /span >
for only $< span jwcid="@Insert" value="ognl:featureDestination.price" >199< /span >
< /p >
< /body >
< /html >
This is the basic interface you will need to know before moving on to finish the tutorial. Once this has been done, things will be easier. Tapestry is a powerful program which can allow you to build Java programs within a short period of time.