Tapestry will create a session, the
first time you request an ASO, even if you just wanted to check whether the values
are default.
Fortunately, Tapestry provides a convenient way of checking whether an ASO
was ever requested (and so created and stored into session by Tapestry) without
initiating its creation.
As soon as you have created an ASO named, say, user, you can also create a private
boolean field named userExists. That is, the name of the ASO field with Exists
appended to it. As soon as the ASO is requested for somewhere in the application,
and so instantiated by Tapestry, this boolean field will be set to true, but before that
its value will be false. Let's use this feature in our application and see how it works.
What if we want to display information about the user on the Start page only when
the User ASO gets instantiated by Tapestry? We can surround the piece of markup
that reports about the user by the If component, like this:
The user is ${user.firstName} ${user.lastName}
This component simply renders its body (i.e. whatever is surrounded by it) when
the condition to which it is bound (userExists in this case) evaluates to true and or
doesn't render anything otherwise.
Pages:
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111