Tutorials to .com

Tutorials to .com » Jsp » Tapestry-hivemind » Tapestry Developer's Guide (1)

Tapestry Developer's Guide (1)

Print View , by: iSee ,Total views: 7 ,Word Count: 1822 ,Date: Thu, 16 Apr 2009 Time: 9:55 PM

Chapter I

tapestry is a comprehensive web application framework, the use of Java. Tapestry is not the application server. Tapestry is used in the application server framework. Tapestry is not the application. Tapestry is a framework to create Web applications. Tapestry does not use JSP. Tapestry is the use of an alternative to JSP. Tapestry is not a scripting environment. Tapestry use Component Object Model, rather than a simple script, to create highly dynamic, interactive web pages.

Tapestry based on the java servlet API Version 2.2, with JDK 1.2 and above versions. Tapestry uses a sophisticated component model, network applications will be layered into the component. There are specific tasks for each component to generate the page (that is, to generate part of HTML pages), and the response HTML query (for example, click on the link, or submit the form).
Tapestry framework to deal with the application of fact to assume processes and server-side clients on all the responsibilities of the state. This allows application developers to focus on aspects of the affairs and that. Tapestry object, methods and properties instead of URLs and query parameters, reconstruction of the concept of web application development.

Copyright @ 2000, 2001, 2002, 2003 The Apache software foundation

1.1.1 script components

Most of the mainstream framework of the network applications are based on the form of a script. These frameworks (often pack into the network or application server) are:
o Sun JavaServer Pages
o Microsoft Active Server Pages
o Allaire ColdFusion
o php
o WebMacro
o FreeMarker
o Velocity
All of these systems are read HTML template file, and in which to deal with the implementation of some. Such treatment by the directives to identify. Directives - HTML template special markings to show that the dynamic behavior.
Each frame there is a scripting language. On JavaServer Pages, is Java. Of ASP, is a Visual basic. Usually, directives are inserted in the HTML scripting language fragments. For example, assume that the fragment from the jsp page, showing part of the shopping cart.

String userName = (String) session.getAttribute ( "userName");
<h1> Contents of shopping cart for
<% = UserName %>:</ h1>

Most of the text, as a static HTML sent directly back to the client browser. Italic text logo script code.
The first chunk of code to extract from the HttpSession user name, the so-called memo books per customer (which is the java Servlet as part of the API; other systems have a similar structure). The second block will be used to insert the value of the expression HTML. Here, expression is the value of the variable userName. It can point to more complex, such as calling methods of Java objects and return a result.
Such examples are often used to show how the script is useful and powerful. In fact, the way it shows the weakness of the script.

First of all, we in the HTML document, there are so many Java code. The problem is ... HTML editor will not understand JSP syntax, or can not confirm that part of the Java script code is correct, or whether it can be compiled. The validity of the test was postponed until viewing the page in the application can be carried out. All the wrong page will be displayed as a run-time error. There are Java code is not natural ... Java code should be fully developed in the IDE.
I have been in the real development of JSP applications, each JSP file is 30% - 50% of Java. Very little performance of Java is a simple logic, like <% = userName%> In this way, the majority of the code block is greater need to 'set' the performance of logic. There are other "good" chunk of code, it is necessary to form through a lot of results for the cycle operation.

In a design team and technical team separate from the environment, no one will feel very happy. The design team is unlikely to know the JSP or Java syntax. Technical team is also difficult to design team by providing the HTML document. Similarly, the two teams do not have good common language to describe their requirements for each page.
Tapestry of a design objective is to minimize the impact of HTML. Many of the system to increase the template for several different values of the directives to be inserted into the HTML in to the conditions to mark the code block, repetition and other operations. Tapestry is quite different; it allows the existing tags in a fully integrated approach to dynamic part marking.

Tapestry components jwcid with any of the HTML tag attributes ( "jwc" on behalf of "Java Web Component"). As compared with the previous example the equivalent of a JSP template Tapestry:

<h1> Contents of shopping cart for
<span jwcid="insertUserName"> John Doe </ span>: </ h1>

Here are defined in the page called insertUserName components. In order to assist the development of HTML, the value of this case, including the "John Doe", but the framework of the use of HTML template, it is automatically edited. Marked <span> a simple Tapestry component that will go where ... it does not conduct any component identification. Will be elsewhere, in the component specification to provide components of the act.
Page specification document insertUserName component part of the definition of what is and what it has done:

<component id="insertUserName" type="Insert"> (1)
<binding name="value" expression="visit.userName"/> (2)
</ component>

(1) id attribute is given the sole component identifier, which matches with the HTML template. type attribute to specify which components to use.
(2) binding identifies how components of the data it needs to be. In this example, insert bound components require the value of its parameters, the value is inserted into the HTML response page. This type of binding (and other), extracted from the visit object userName attribute (visit object: the Center, as defined in the application object to store in the Tapestry application of the majority of the server-side state).

Tapestry is really good at doing some complex things, rather than simply to generate the output. For example, we assume that only when the user something to the car when the checkout button should be enabled. In the JSP world, may be like this:

boolean showLink;
String imageURL;
showLink = applicationObject.getHasCheckoutItems ();
if (showLink)
imageURL = "/ images / Checkout.gif";
imageURL = "/ images / Checkout-disabled.gif";

if (showLink)
String linkURL;
linkURL = response.encodeURL ( "/ servlet / checkout");%>
<a href ="<%= linkURL%> ">
<img border = 0 src ="<%= imageURL%> "alt =" Checkout "> <%
if (showLink)
out.println ( "</ a>");

It is assumed that, applicationObject determine whether the user entered any settlement project. It can be assumed that this object from a servlet to provide the control of, or placed in the HttpSession.
Tapestry of the corresponding HTML template is even more simple:
<a jwcid="checkoutLink"> <img jwcid="checkoutButton" alt="Checkout"/> </ a>
More pages of the specification document:

<component id="checkoutLink" type="PageLink"> (1)
<static-binding name="page"> Checkout </ static-binding>
<binding name="disabled" expression="visit.cartEmpty"/> (2)
</ component>

<component id="checkoutButton" type="Rollover"> (3)
<binding name="image" expression="assets.checkout"/>
<binding name="disabled" expression="assets.checkoutDisabled"/>
</ component>

<external-asset name="checkout" URL="/images/Checkout.gif"/> (4)
<external-asset name="checkoutDisabled" URL="/images/Checkout-disabled.gif"/>

(1) is a checkoutLink components PageLink, the components in the application to create a link to other pages. Tapestry is responsible for generating the appropriate URL.
(2) will be set to disable parameter to allow the closure of the link; here Cart is empty when it was closed.
(3) Insert a Rollover Image components; it must be linked in a number of components inside (for example, PageLink), and whether to link to or can not be sensitive; When not set, the insert another image. Rollover components not shown here to generate the capacity of the dynamic effect of the mouse.
(4) Tapestry use of abstract, aasets, to identify images, stylesheets and other resources. Rollover component is to be referred to the assets, rather than the URL.

This example will focus on, JSP developers must consider the character of a character to generate HTML. Further example, Java code and HTML quickly become out of proportion. Instead, Tapestry components to consider the development of behavior, and an elegant way to dynamically specify their behavior.

tapestry & hivemind Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.