You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dustin Frazier <du...@philanthropix.org> on 2003/08/30 04:41:16 UTC

persistent page properties

First the heart of the question, then some background:  Does Tapestry allow
you to declare a persistent page property in your .page file when you also
have an explicit setter and getter (using a private field) in your Java code?
Does it actually still persist the property value in that case (and restore it
when the page is restored from the pool)?

I'm trying to do a very standard search form, search results, and details
page.  I have a search form component which takes some text, passes it to our
db code and gets back a data structure which represents the search results
(basically a count and a list of ids).  In the listener method for the search
form component, I get an instance of my search results page via
cycle.getPage(), set the search data structure on it (into a persistent
property), and activate the page.

The search results page displays its results as a table built with a Foreach
that loops over a list of *actual objects* which is lazily initialized using a
single query when the object list is first requested by the Foreach.  Each row
in the results table has an ActionLink to show a details page for the given
object.  The listener method for the link looks up the "current" object
(during rewind of the results page), gets an instance of my details page, sets
the object on the page, and activates the page.

So, here's my issue.  The list of actual objects on the results page needs to
persist, because otherwise the query to fetch them using the ids will happen
twice, once when rendering the results page, and again during the rewind after
the user clicks one of the details links.  I have to do the query either in
the getter for the object list or the setter for the list of ids.
Unfortunately, that seems to lose when I also declare the properties as
persistent.

If you're still with me and have any insights, I'd much appreciate it...  I'm
guessing perhaps I have to do this particular persistent property the old
school way, but I'm hoping there's a more clever solution.

Thanks!!!

Dustin


RE: persistent page properties

Posted by Paul Ferraro <pa...@softhome.net>.
These pages should help demystify the dynamic sub-class generation
magic:

http://jakarta.apache.org/tapestry/doc/TapestryUsersGuide/state.page-properties.html
http://jakarta.apache.org/tapestry/doc/TapestryUsersGuide/state.manual-page-properties.html

Hope this helps,

Paul

On Fri, 2003-08-29 at 23:49, Dustin Frazier wrote:
> Almost.  :)  The problem with your solution (unless I'm missing something) is
> that, when a new search gets executed, the new list of ids gets set from the
> search form component, but the getter used by the search results page doesn't
> know that the list of objects needs to be re-fetched (it's not null, just out
> of date).  I could set the list of objects to null whenever the list of ids is
> set, but that sounds a lot like...
> 
> I solved the problem by creating a method on the results page to fetch the
> objects from the list of ids, and I only call this method from the search form
> component right after it sets the list of ids on the results page.  Kinda
> clunky, and it forces to query right away, which is why I was hoping for
> something a little more elegant and lazy.
> 
> Just so I understand, what prevents Tapestry from doing it's subclassing magic
> when you've written explicit setters and/or getters in your Java code?
> 
> Dustin
> 
> -----Original Message-----
> From: Harish Krishnaswamy [mailto:hkrishnaswamy@comcast.net] 
> Sent: Friday, August 29, 2003 9:34 PM
> To: Tapestry users
> Subject: Re: persistent page properties
> 
> 
> The common solution in such situations has been to use a synthetic 
> property. So, you declare a persistent property via 
> property-specification and use it for storage. Write a getter in your 
> class to build the list and use this getter in the form. This getter can 
> store the retrieved / built list in the synthetic property created via 
> property-specification and later retrieve it if it is available or build 
> it again if not available. Hope this solves your problem.
> 
> -Harish
> 
> Dustin Frazier wrote:
> 
> >First the heart of the question, then some background:  Does Tapestry 
> >allow you to declare a persistent page property in your .page file when 
> >you also have an explicit setter and getter (using a private field) in 
> >your Java code? Does it actually still persist the property value in 
> >that case (and restore it when the page is restored from the pool)?
> >
> >I'm trying to do a very standard search form, search results, and 
> >details page.  I have a search form component which takes some text, 
> >passes it to our db code and gets back a data structure which 
> >represents the search results (basically a count and a list of ids).  
> >In the listener method for the search form component, I get an instance 
> >of my search results page via cycle.getPage(), set the search data 
> >structure on it (into a persistent property), and activate the page.
> >
> >The search results page displays its results as a table built with a 
> >Foreach that loops over a list of *actual objects* which is lazily 
> >initialized using a single query when the object list is first 
> >requested by the Foreach.  Each row in the results table has an 
> >ActionLink to show a details page for the given object.  The listener 
> >method for the link looks up the "current" object (during rewind of the 
> >results page), gets an instance of my details page, sets the object on 
> >the page, and activates the page.
> >
> >So, here's my issue.  The list of actual objects on the results page 
> >needs to persist, because otherwise the query to fetch them using the 
> >ids will happen twice, once when rendering the results page, and again 
> >during the rewind after the user clicks one of the details links.  I 
> >have to do the query either in the getter for the object list or the 
> >setter for the list of ids. Unfortunately, that seems to lose when I 
> >also declare the properties as persistent.
> >
> >If you're still with me and have any insights, I'd much appreciate 
> >it...  I'm guessing perhaps I have to do this particular persistent 
> >property the old school way, but I'm hoping there's a more clever 
> >solution.
> >
> >Thanks!!!
> >
> >Dustin
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
> >  
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


Re: persistent page properties

Posted by Harish Krishnaswamy <hk...@comcast.net>.
>Just so I understand, what prevents Tapestry from doing it's subclassing magic
>when you've written explicit setters and/or getters in your Java code?


That's a good question, I can't think of any.

-Harish






RE: persistent page properties

Posted by Dustin Frazier <du...@philanthropix.org>.
Almost.  :)  The problem with your solution (unless I'm missing something) is
that, when a new search gets executed, the new list of ids gets set from the
search form component, but the getter used by the search results page doesn't
know that the list of objects needs to be re-fetched (it's not null, just out
of date).  I could set the list of objects to null whenever the list of ids is
set, but that sounds a lot like...

I solved the problem by creating a method on the results page to fetch the
objects from the list of ids, and I only call this method from the search form
component right after it sets the list of ids on the results page.  Kinda
clunky, and it forces to query right away, which is why I was hoping for
something a little more elegant and lazy.

Just so I understand, what prevents Tapestry from doing it's subclassing magic
when you've written explicit setters and/or getters in your Java code?

Dustin

-----Original Message-----
From: Harish Krishnaswamy [mailto:hkrishnaswamy@comcast.net] 
Sent: Friday, August 29, 2003 9:34 PM
To: Tapestry users
Subject: Re: persistent page properties


The common solution in such situations has been to use a synthetic 
property. So, you declare a persistent property via 
property-specification and use it for storage. Write a getter in your 
class to build the list and use this getter in the form. This getter can 
store the retrieved / built list in the synthetic property created via 
property-specification and later retrieve it if it is available or build 
it again if not available. Hope this solves your problem.

-Harish

Dustin Frazier wrote:

>First the heart of the question, then some background:  Does Tapestry 
>allow you to declare a persistent page property in your .page file when 
>you also have an explicit setter and getter (using a private field) in 
>your Java code? Does it actually still persist the property value in 
>that case (and restore it when the page is restored from the pool)?
>
>I'm trying to do a very standard search form, search results, and 
>details page.  I have a search form component which takes some text, 
>passes it to our db code and gets back a data structure which 
>represents the search results (basically a count and a list of ids).  
>In the listener method for the search form component, I get an instance 
>of my search results page via cycle.getPage(), set the search data 
>structure on it (into a persistent property), and activate the page.
>
>The search results page displays its results as a table built with a 
>Foreach that loops over a list of *actual objects* which is lazily 
>initialized using a single query when the object list is first 
>requested by the Foreach.  Each row in the results table has an 
>ActionLink to show a details page for the given object.  The listener 
>method for the link looks up the "current" object (during rewind of the 
>results page), gets an instance of my details page, sets the object on 
>the page, and activates the page.
>
>So, here's my issue.  The list of actual objects on the results page 
>needs to persist, because otherwise the query to fetch them using the 
>ids will happen twice, once when rendering the results page, and again 
>during the rewind after the user clicks one of the details links.  I 
>have to do the query either in the getter for the object list or the 
>setter for the list of ids. Unfortunately, that seems to lose when I 
>also declare the properties as persistent.
>
>If you're still with me and have any insights, I'd much appreciate 
>it...  I'm guessing perhaps I have to do this particular persistent 
>property the old school way, but I'm hoping there's a more clever 
>solution.
>
>Thanks!!!
>
>Dustin
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: persistent page properties

Posted by Harish Krishnaswamy <hk...@comcast.net>.
The common solution in such situations has been to use a synthetic 
property. So, you declare a persistent property via 
property-specification and use it for storage. Write a getter in your 
class to build the list and use this getter in the form. This getter can 
store the retrieved / built list in the synthetic property created via 
property-specification and later retrieve it if it is available or build 
it again if not available. Hope this solves your problem.

-Harish

Dustin Frazier wrote:

>First the heart of the question, then some background:  Does Tapestry allow
>you to declare a persistent page property in your .page file when you also
>have an explicit setter and getter (using a private field) in your Java code?
>Does it actually still persist the property value in that case (and restore it
>when the page is restored from the pool)?
>
>I'm trying to do a very standard search form, search results, and details
>page.  I have a search form component which takes some text, passes it to our
>db code and gets back a data structure which represents the search results
>(basically a count and a list of ids).  In the listener method for the search
>form component, I get an instance of my search results page via
>cycle.getPage(), set the search data structure on it (into a persistent
>property), and activate the page.
>
>The search results page displays its results as a table built with a Foreach
>that loops over a list of *actual objects* which is lazily initialized using a
>single query when the object list is first requested by the Foreach.  Each row
>in the results table has an ActionLink to show a details page for the given
>object.  The listener method for the link looks up the "current" object
>(during rewind of the results page), gets an instance of my details page, sets
>the object on the page, and activates the page.
>
>So, here's my issue.  The list of actual objects on the results page needs to
>persist, because otherwise the query to fetch them using the ids will happen
>twice, once when rendering the results page, and again during the rewind after
>the user clicks one of the details links.  I have to do the query either in
>the getter for the object list or the setter for the list of ids.
>Unfortunately, that seems to lose when I also declare the properties as
>persistent.
>
>If you're still with me and have any insights, I'd much appreciate it...  I'm
>guessing perhaps I have to do this particular persistent property the old
>school way, but I'm hoping there's a more clever solution.
>
>Thanks!!!
>
>Dustin
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>  
>