Apache
  Home arrow Apache arrow Page 5 - Apache Tapestry: ASO and More Componen...
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 
IBM Developerworks
 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: ASO and More Components
By: Alexander Kolesnikov
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 12
    2007-05-21

    Table of Contents:
  • Apache Tapestry: ASO and More Components
  • Creating hivemodule.xml
  • AddCelebrity page
  • Creating the template with new components
  • Continuing to configure the application

  • 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

    Dell PowerEdge Servers

    Apache Tapestry: ASO and More Components - Continuing to configure the application
    (Page 5 of 5 )

    Before going further, let's configure TextField components for the first and last names. This is easy; you have already done this in the previous application, so I will simply show the relevant pieces of code. In the page template:

    ...

    <input type="text" jwcid="firstName"/>

    ...

    <input type="text" jwcid="lastName"/>

    ...

    In the page specification:

    <component id="firstName" type="TextField">

        <binding name="value" value="firstName"/>

    </component>

    <component id="lastName" type="TextField">

        <binding name="value" value="lastName"/>

    </component>

    And in the page class:

    public abstract String getFirstName();

    public abstract String getLastName();

    If you run the application again, you will notice that whatever you enter for the names and whichever gender you selected, these values are retained after the form was submitted and the page redisplayed. This is very simple, but it might be worth thinking about. The values we have entered were delivered to the page class and put into its properties, and when the page was redisplayed after form submission, Tapestry checked which values are stored in the properties of the page class and put those values into the components connected to those properties.

    Now, let's configure the next component, the one used to select an occupation for the newly added celebrity. Here is its mock up:

    <select>

       <option>Actor/Actress</option>

       <option>Wine-maker</option>

       <option>Programmer</option>

    </select>

    To display a dynamic version of an HTML <select> element in a Tapestry application, we use the PropertySelection component. Mark this <select> with a Tapestry ID:

    <select jwcid="occupation">

    and then configure it in the page specification:

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

        <binding name="model" value="occupationsModel"/>

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

    </component>

    As you can see, this component has two bindings, model and value. As for the value, we are familiar with it from the other components. This binding will pass to the page class the value selected by the user, and when the page is rendered for the first time, it will provide the initial value for the component. Let's configure the appropriate property in the page class:

    public abstract String getOccupation();

    The model binding is new to us. Basically, it provides to the component the options to display, but the way how it does this might seem a little bit cumbersome at first. Here is the method that the occupation component will expect to find in the page class:

    public IPropertySelectionModel getOccupationsModel() {

            // Some code that creates and returns an implementation

            // of IPropertySelectionModel interface

    The return value, IPropertySelectionModel, is an interface that has several methods in it, and Tapestry provides a few implementations of this interface. Today we shall use the simplest implementation, but in one of the upcoming parts of the tutorial I am going to show how to unleash the full power of IPropertySelectionModel and explain the logic behind this seemingly cumbersome but potentially very flexible way of providing the options to display. For now, just add to the page class the following method:

    public IPropertySelectionModel getOccupationsModel() {

        String[] occupations = {"Actor/Actress",

           "Wine-maker", "Programmer"};

        return new StringPropertySelectionModel(occupations);

    }

    We have simply created an array of strings and then used it to create an instance of StringPropertySelectionModel, the simplest of IPropertySelectionModel implementations.

    Run the application and it should work properly. Well, at the first glance the AddCelebrity page looks exactly as its mock up, but if you select some occupation other than the first, and then submit the form, the selected value will be redisplayed. This this means that the page in your browser and the page class on the server are speaking to each other.

    Have a look at the source of the page in your browser, and you will see that the <select> for specifying the occupation was rendered like this:

    <select name="occupation" id="occupation">

      <option value="0">Actor/Actress</option>

      <option value="1">Wine-maker</option>

      <option value="2">Programmer</option>

    </select>

    You can see that each occupation has a label, displayed to the user, and a value associated with that label. This is something we are going to explore soon, but for today we have already covered enough ground.

    What comes next

    In the next part of the tutorial we are going to complete the AddCelebrity page by adding a DatePicker component to it, and also some code to actually create a new Celebrity object and "record" it into the DataSource.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · i have not so much experience with tapestry but i love it more than anything else. ...
       · Application State Objects are very useful in any Tapestry application. This issue...
       · Thank you very much! I am writing an issue on AJAX components by the way, and I am...
       · I have completed all this series of Tapestry tutorial in just two days and now I...
       · Thats great, but the tutorial is very far from completion :)The most interesting...
       · you mean issue 14 is online??? it is super! wow!!! but i didn found it:)I'm fan...
       · No, this means I have submitted it to the publisher :)It takes some time to edit...
       · :( I'm risking to ask you about new components. May I?Is it possible in an...
       · I am not sure what you want to achieve, but one solution would be to have a method...
       · Sorry, but DevShed delays the publication of the four issues I have already...
       · OK, so i have another error and i just can not figure it out. it says:"Unable to...
       · OK, I figured it out. The source read .Home instead of .AddCelebrity. Sometimes,...
       · Hi! Is there an alternative to using @InjectState? just like instead of @InjectPage,...
     

       

    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




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