Home arrow Apache arrow Page 4 - PropertySelection and IPropertySelectionModel in Apache Tapestry

One More Detail - Apache

We already encountered PropertySelection in one of the previous articles so we know that it is a Tapestry component used to display a drop-down list, allowing the user to choose one of multiple options. You might think that the way in which options are provided to this component (through its model binding) is somewhat cumbersome when all you need to do is select one of a few strings. However, PropertySelection was designed with a great deal of power and flexibility in mind, and I hope that today you will appreciate this.

TABLE OF CONTENTS:
  1. PropertySelection and IPropertySelectionModel in Apache Tapestry
  2. Configuring PropertySelection
  3. Working on the Model
  4. One More Detail
  5. So what have we done?
By: Alexander Kolesnikov
Rating: starstarstarstarstar / 24
June 12, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Is everything ready now? Not yet. Try to run the application, and when the Home page appears for the first time, you will see something that is not very nice:

AS soon as the application started, the Home page requested an instance of the Celebrity class to be injected into it as a celebrityOfTheWeek ASO. Tapestry created such an instance and gave it to the Home page. However, this instance is empty; all its properties, including firstName and lastName have their default values, null. Hence the result.

What we actually want is to show the celebrity of the week only if it was already chosen. This sounds like we need an If component. But what will be the criterion of whether the ASO was filled in with proper values or not? Let's say the first name should have some value stored in it. All we need to do is surround the fragment of the Home.html template displaying the celebrity of the week with an If component, like so:

<div jwcid="@If" condition="ognl:theCelebrity.firstName != null">

  <p><strong>Celebrity of the Week</strong>:

    <span jwcid="celebrityOfTheWeek">John Smith</span></p>

</div>

Note that I am intentionally mixing together implicit and declared components. This might be not the best approach in a real life application, but here it gives me an opportunity to show you both ways. Also, you have a chance to develop a feeling for where your personal threshold between implicit and declared components lies.

If you run the application now, it should work properly. When the Home page is displayed for the first time, it has no information about the Celebrity of the Week on it. Go to the list of Celebrities, grab the glorious title attached to one of them, and you'll see his or her name appearing on the Home page.

If you now navigate to the CelebritiesList page again, you'll see that the celebrity you've just selected appears as a default choice in the drop-down list. This means that the connection between the PropertySelection component on the page and an ASO in the session on the server remains active.



 
 
>>> More Apache Articles          >>> More By Alexander Kolesnikov
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

APACHE ARTICLES

- Apache Unveils Cassandra 1.2
- Apache on ARM Chips? Dell and Calxeda Help M...
- The Down Side of Open Source Software
- VMware Unveils Serengeti for Apache Hadoop
- SAP Takes Steps to Improve Hadoop Integration
- Looking to Hone Apache Hadoop Skills?
- How to Install Joomla on WAMPP
- Working with XAMPP and Wordpress
- GUI Available for Apache Camel
- Reduce Server Load for Apache and PHP Websit...
- Creating a VAMP (Vista, Apache, MySQL, PHP) ...
- Putting Apache in Jail
- Containing Intrusions in Apache
- Server Limits for Apache Security
- Setting Permissions in Apache

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: