Apache
  Home arrow Apache arrow Page 3 - Making a CelebrityCollector with Apach...
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

Making a CelebrityCollector with Apache Tapestry: the For Component
By: Alexander Kolesnikov
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 24
    2007-05-09

    Table of Contents:
  • Making a CelebrityCollector with Apache Tapestry: the For Component
  • Creating an object model
  • Creating pages
  • The For component

  • 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

    PCmover - $15 Off with Coupon Code CJPH7Q

    Making a CelebrityCollector with Apache Tapestry: the For Component - Creating pages
    (Page 3 of 4 )

    Making Home.html a Tapestry template is easy. All we need to do is convert the existing HTML link into an already familiar PageLink component, and it is okay to do this implicitly:

    <p><a href="" jwcid="@PageLink" page="CelebritiesList">

        List Celebrities</a></p>

    You might want to run the project at this point and see if clicking on the link produces the desired result. It should.

    As the Home page is so simple and its page specification remains empty, we don’t actually need any Home page class for it. In fact, you could simply remove the class attribute from the page specification:

    <?xml version="1.0"?>

    <!DOCTYPE page-specification PUBLIC

        "-//Apache Software Foundation//Tapestry Specification 4.0//EN"

        "http://tapestry.apache.org/dtd/Tapestry_4_0.dtd">

    <page-specification>

    </page-specification>

    In this case Tapestry will use its BasePage class as a Home page class. However with time, as the CelebrityCollector application becomes more complex, we might decide to add something to the Home page. So I suggest leaving in place both the Home.page specification and the Home.java class; it doesn’t matter that they are empty so far.

    Converting Details.html is also straightforward. All we need is a number of Insert components and another PageLink. Let’s suppose for now that we have a celebrity property already available in the Details class. We shall add it in a few minutes. Here is the Details page template:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

     

    <html>

      <head>

          <title>Celebrity Collector: <span jwcid="fullName">

              John Smith</span></title>

      </head>

      <body>

     

      <h2><span jwcid="fullName2">John Smith</span></h2>

         

      <table>

          <tr>

              <td><b>Birthday:</b></td>

              <td><span jwcid="birthday">01/01/1950</span></td>

          </tr>

          <tr>

              <td><b>Occupation:</b></td>

              <td><span jwcid="occupation">Actor</span></td>

          </tr>

      </table>

      <p><a href="" jwcid="@PageLink" page="CelebritiesList">

           Back to the list</a></p>

     

      </body>

    </html>

    And here is the corresponding Details page specification (note that all Insert components are configured in the specification while PageLink is defined implicitly):

    <?xml version="1.0"?>

    <!DOCTYPE page-specification PUBLIC

        "-//Apache Software Foundation//Tapestry Specification 4.0//EN"

        "http://tapestry.apache.org/dtd/Tapestry_4_0.dtd">

    <page-specification class="com.devshed.tapestry.celebrities.Details">

     

        <component id="fullName" type="Insert">

            <binding name="value"

              value="celebrity.firstName + ' ' + celebrity.lastName"/>

        </component>

       

        <component id="fullName2" copy-of="fullName"/>

       

        <component id="birthday" type="Insert">

            <binding name="value" value="celebrity.dateOfBirth"/>

        </component>

     

        <component id="occupation" type="Insert">

            <binding name="value" value="celebrity.occupation"/>

        </component>

       

    </page-specification>

    Before discussing how components were configured, let’s add a celebrity property to the Details page by providing abstract public getter and setter methods:

    public abstract class Details extends BasePage {

       

        public abstract Celebrity getCelebrity();

        public abstract void setCelebrity(Celebrity c);

       

    }

    At some point, we are going to use the setter to assign some Celebrity object to this property, but for now we don’t care when and where that will be done. Let’s concentrate on how different Insert components were configured in the page specification or, most importantly, on their bindings.

    The component named occupation is the simplest one. It is bound to the OGNL expression

    celebrity.occupation

    Which means that to obtain a value to display, Tapestry will first invoke the getCelebrity() method of the Details class. We have provided this method, and although we made it abstract, Tapestry will take care of creating a concrete implementation of it at runtime. So we’ll get a Celebrity object as a return value from this method.

    Then, according to the rules of OGNL, Tapestry will try to invoke the getOccupation() method on the Celebrity object. Sure enough, we have provided such method, and it returns a String. That same string will be displayed by the component then.

    The birthday component is different in only one respect: its binding returns a Date. To display it, Tapestry will invoke the Date’s toString() method which will produce… well, some result. In fact, we can have complete control of how the value is displayed by an Insert component by using its format binding, but let me delay the explanation until the next article.

    In two cases we want to display the full name of the celebrity: first, in the title element of the resulting HTML page (this is the piece of information displayed by a browser’s title bar), and second, in the header of the page. The fullName component does the job in the title element. Have a look at its binding expression:

    celebrity.firstName + ' ' + celebrity.lastName

    According to this OGNL expression, Tapestry will obtain the first and the last names of the celebrity by invoking appropriate methods of the Details and Celebrity classes and then glue both names together leaving a blank space between them. So you see, OGNL can be quite useful.

    In order to insert the full name into the page header, we use the fullName2 component. As we need exactly the same result, we could use exactly the same binding – but there is a more rational way to achieve the desired result. We can simply state that fullName2 component is a copy of the fullName component, and this is exactly what we are doing here. 

    Finally, we are coming to the CelebritiesList page, and here we are going to need the new component named For. Let’s see what it can do for us.

    More Apache Articles
    More By Alexander Kolesnikov


       · In this issue we are beginning to build a new application, and I am going to use it...
       · <property name = "currentCelebrity"/> <component id="eachCelebrity" ...
       · Please see Alexander's previous article for its...
       · public abstract class CelebritiesList extends BasePage { public List...
       · Why not? Count the brackets ;)
       · So, I get the error below. I was wondering if you could please also give some...
       · Here is the HTML code that got left out from above: <tr...
       · Any takers?? Alex?
       · OK, so the porblem seems to be that I can not put a tapestry component in a table...
       · <property name = "currentCelebrity"/>The above is equivalent to creating a...
     

       

    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 3 hosted by Hostway