Apache
  Home arrow Apache arrow Page 2 - Apache Tapestry 4 Tutorial
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
APACHE

Apache Tapestry 4 Tutorial
By: Alexander Kolesnikov
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 113
    2007-04-03

    Table of Contents:
  • Apache Tapestry 4 Tutorial
  • JavaServer Pages came to the rescue
  • The Holy Trinity of software development
  • Why Tapestry?
  • Tapestry and prejudices

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Apache Tapestry 4 Tutorial - JavaServer Pages came to the rescue
    (Page 2 of 5 )

    Technically, a JSP page is just the same servlet as it gets compiled into a servlet behind the scenes before it is shown to a Web application's user. However, from the developer's point of view, working with JSP pages is a completely different thing. You can have as much HTML in your page as needed, and if you want to use some Java code, you just insert a scriptlet, as in this example:

    <p>Some nicely formatted HTML goes here</p>

    <%

       // And here is some Java code as needed by the page  

       String name = request.getParameter("firstName");

    %>

    <p>Hello <%= name %></p>

    This was the original design of JSP technology. What can be better: designers can work on their pieces of HTML, Java programmers can work on their pieces of code, and whatever is generated in the code can be easily inserted into HTML using a simple notation.

    But this holds true only for simple pages with limited functionality. As the dynamic part of the page becomes more complex, Java unavoidably gets mixed with HTML. Have a look at another example:

    <%

     for (int i = 1; i <= metaData.getColumnCount(); i++) {

      if (metaData.getColumnType(i) == Types.DOUBLE) {

           %>

              <td align='right'>

                  <%= formatter.format(resultSet.getDouble(i)) %>

              </td>

           <%

      } else {

           %>

              <td>

                  <%= resultSet.getObject(i).toString() %>

              </td>

           <%

      }

     }

    %>

    If you write such a page yourself and you know both HTML and Java, no problem, you can do this. However, many Java Web applications are created by a group of people, often with narrow specializations, and this kind of Java/HTML cocktail makes both designers and developers unhappy.

    As a result, it was decided that scriptlets are a bad thing, and they should not be used. Instead, a set of tags was provided. If designers don't like Java code, they should be much happier working with tags.

    The idea was to have all Java code in some separate Java class, referred to as a bean, and then you can use that bean from your JSP page by using a few simple tags like these:

    <jsp:useBean id="myBean" class="com.example.MyBean"/>

    Hello <jsp:getProperty name="myBean" property="firstName"/>

    Again, the idea wasn't bad, especially for simple pages. But for anything more complex the existing set of tags was severely limiting.

    Of course, there was an opportunity to write your own custom tags and do in them everything you can imagine. But writing custom tags isn't for the fainthearted; one would need a pretty good understanding of the details of JSP technology to do that. Also, if you wanted to output some HTML in your custom tag, you would have to print it out in the same way as in a servlet.

    Still, many developers produced numerous libraries of custom tags, and one such library, JSTL (JavaServer Pages Standard Tag Library), became a part of JSP standard.

    However, obstinate developers kept using scriptlets in their JSP pages, saying that even the best custom tags do not give them the flexibility they require. This finally led to yet another addition to JSP - the Expression Language (EL).

    Expression Language is truly powerful and convenient. The only problem is that to get rid of Java code inside of JSP pages, three different notations were introduced: standard tags, custom tags and EL expressions. All three have slightly different logic, naming scheme and rules, so that learning them in detail can be quite a nuisance! Have a look at this brief example, taken from real life code:

    <tr>

       <c:forEach var="column"   

           items="ID,Name,Quantity,Price,Total">

              <th><c:out value="${column}"/></th>

       </c:forEach>

    </tr>

    Does this look like a clean separation between HTML and code? I wouldn't say so.

    Still, JavaServer Pages technology solved the tasks for which it was created. However, this is a rather low level technology. Creating a Web application from scratch using JSP pages and servlets required writing a lot of "boiler plate code" again and again, or copying and pasting large chunks of code - what a reliable source of hard to find errors!

    Some kind of framework was required that would have all the basic stuff already written and would provide some sort of architectural solution for a future Java Web application. A number of such frameworks appeared; the most famous of them is Apache Struts. Typically, they embodied the MVC (Model-View-Controller) pattern, widely regarded as a panacea for many problems of software development.

    More Apache Articles
    More By Alexander Kolesnikov


       · Dear readers,Welcome to the world of Apache Tapestry. I am quite passionate...
       · Excellent article, Alexander. Difficult for me in parts, but at the leading edge....
       · But what exactly do you find difficult? I wonder if it can be written in such a way...
       · Great article pal:)I just went and bought that book under your advice and it...
       · I am referencing my Tapestry dissertation somewhere in the article. Normally, people...
       · Thanks, Rob,Just note that Kent Tong explains how to deal with "bare-bones"...
     

       

    APACHE ARTICLES

    - Putting Apache in Jail
    - Containing Intrusions in Apache
    - Server Limits for Apache Security
    - Setting Permissions in Apache
    - Installing Apache
    - Apache Installation and Configuration
    - Apache Tapestry and Custom Components: DateI...
    - Tapestry and AJAX: Autocompleter and InlineE...
    - PropertySelection and IPropertySelectionMode...
    - The DatePicker and Shell Components of Apach...
    - Apache Tapestry: ASO and More Components
    - Apache Tapestry and DirectLink, IoC and DI
    - Making a CelebrityCollector with Apache Tape...
    - Apache Tapestry and Listener Methods, Condit...
    - The Properties of Tapestry Pages

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway