PropertySelection and IPropertySelectionModel in Apache Tapestry - One More Detail (Page 4 of 5 )
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.
Next: So what have we done? >>
More Apache Articles
More By Alexander Kolesnikov