Apache
  Home arrow Apache arrow Page 3 - Apache Tapestry and Listener Methods, ...
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 and Listener Methods, Conditional Components and PageLink
By: Alexander Kolesnikov
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 19
    2007-05-08

    Table of Contents:
  • Apache Tapestry and Listener Methods, Conditional Components and PageLink
  • Passing information to the next page
  • Conditional components
  • PageLink component
  • Deploying 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Apache Tapestry and Listener Methods, Conditional Components and PageLink - Conditional components
    (Page 3 of 5 )

    We want to show the hidden truth only if the secret word was guessed properly. Wouldn’t it be natural to use the Tapestry’s If component for this purpose? The If component has one binding, the condition to evaluate, but since our Secret page is very simple in its design, I think it will be okay to define this component implicitly, like so:

    <div jwcid=”@If” condition=”ognl:theWord == ‘abrakadabra’”>

       <!—Stuff to show if everything is OK --/>

    </div>

    Previously, we have used a span HTML element as a placeholder for our Tapestry component. Now we use div for the same purpose, as it is more logical to surround a block of markup with a div. The If component will simply show or not show the contents of the div depending on whether its condition evaluates to true or to false.

    We have used the ognl prefix to specify that the value for the condition attribute should be treated as an OGNL expression. If we forget to do this (which I do quite often) the value will be treated verbatim and then anything non-empty will be understood as true.

    Then we are comparing the word that was passed from the Home page with the hard-coded word “abrakadabra” (you can use any other word of course!). The word to compare with is put into single quotes as double quotes are already used to surround the value of the condition attribute. Of course, hard-coding anything like this would not be a good idea in any real-life application, but we’ll leave it just like that for now, for simplicity’s sake.

    So, when the user enters the magical word “abrakadabra” at the Home page and presses the Submit button, the hidden truth is displayed by the Secret page, but if the user enters anything else… The Tapestry’s Else component will take care of displaying the alternative content.

    The Else component is very simple, it doesn’t require any bindings, and so it is natural to define it implicitly, like so:

    <div jwcid=”@Else”>

       <!-- An alternative content goes here -->

    </div>

    Of course, to work properly, an Else component has to follow an If component. Now the HTML template for the Secret page should look like this:

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

     

    <html>

      <head>

        <title>Guess Result</title>

      </head>

      <body>

          <div jwcid="@If" condition="ognl:theWord == 'abrakadabra'">

              <!-- This will be shown if the guess was successful -->

              <h2>Congratulations!</h2>

              <p>You have guessed the secret word properly,

              and here is the hidden wisdom:</p>

              <p><i>Lorem ipsum dolor sit amet, consectetur

                      adipisicing elit, sed do eiusmod tempor

              incididunt ut labore et dolore magna aliqua.</i></p>    

          </div>

          <div jwcid="@Else">

              <!-- And this will be shown if case of failure -->

              <h2>This was a wrong word</h2>

              <p><a rel="nofollow" target="_blank" href = "">Go back and try again.</a></p>

          </div>

      </body>

    </html>

    Run the application, and it should work properly: if you submit the correct word, the hidden truth is shown, otherwise you are prompted to try again.

    More Apache Articles
    More By Alexander Kolesnikov


       · By the way I am hosting my website at the same provider I've mentioned in the...
       · This is a TestThis is a TestThis is a TestThis is a TestThis is a TestThis is a...
       · HiI couldn't run my application with the following sentence in Secret...
       · My guess is that you had a setter but didn't have a getter. Tapestry needs to...
       · HiYes, it includes the getter abstract method.My class is:public abstract...
       · Ah! This might be the problem. You need to accept a parameter in the...
       · It works!. I supposed an abstract method (with Tapestry) shouldn't have parameters....
       · Okay, thats good.Well, there should be at least one article every week....
       · Can you plese explain the folowing line of code:Secret nextPage =...
       · First of all, we ask Tapestry to give us a page named "Secret": getPage("Secret")....
     

       

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