You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Gurps <g...@gurpal.co.uk> on 2006/11/02 14:22:58 UTC
RE: how to persist id parameter?
Patrick Casey wrote:
>
>
> I'd warn against using persistent ID objects as keys for edit forms.
> The problem is that Tapestry persists properties on a page/session key. So
> for any given session, page "foo" has a set of persistent properties.
>
> Lets say though that you have a page called "editUser".
>
> You have a list of users.
> User clicks open in new tab on bob.
> editUser -> Bob opens up. Key = Bob
> User clicks open in new tab on ted.
> editUser -> ted opesns up. Key = Ted.
> User update's bob's entry.
> User presses save.
> Ted's record just got updated.
>
> The solution turns out to be stuffing the edited in the form via a
> hidden field. Stuff it on "top" of the form so it bootstraps the record
> during rewind just like you're doing, but don't trust the page to persist
> it
> for you; send it out with the form so you can guarantee it comes back with
> the form.
>
> --- Pat
>
>> -----Original Message-----
>> From: Steven Wisener [mailto:swisener@gmail.com]
>> Sent: Tuesday, July 19, 2005 7:26 PM
>> To: Tapestry users; Jer Kah
>> Subject: Re: how to persist id parameter?
>>
>> I think he got that far...the problem is posting back to the form. I
>> made the ID property persistent to solve the problem (it is stored in
>> the session, so it won't be null on the second page render), but you
>> should be able to use a Hidden component as well:
>>
>> In your form, add:
>>
>> <span jwcid="@Hidden" value="ognl:id"
>> listener="ognl:listeners.initObject"
>> />
>>
>> If the rest of the components rely on the object being initialized,
>> make sure it appears first in the form. Your page class should look
>> something like this:
>>
>> public void pageBeginRender(PageEvent event) {
>> if (getId() != null) {
>> initObject(event.getRequestCycle());
>> }
>> }
>>
>> public void initObject(IRequestCycle cycle) {
>> setObject(getObjectFromDatabase(getId());
>> }
>>
>> So here's the basic flow: The first time the page is loaded, the id
>> property is set and initObject loads it. When the form is submitted,
>> the id is not set yet in pageBeginRender, so initObject is not called.
>> When the render hits the Hidden component however, initObject is
>> called because it is its listener method. As long as you only need the
>> object loaded after the Hidden component is rendered in the rewind,
>> you should be golden. I haven't actually tested this out yet, but I
>> think it should work.
>>
>> --Steven
>>
>>
>
>
>
how exactly would you "stuff" the parameter?
Thanks
--
View this message in context: http://www.nabble.com/how-to-persist-id-parameter--tf129027.html#a7133422
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org