You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Hugo Palma <hu...@gmail.com> on 2008/01/18 17:44:14 UTC

T5: Strategy for pages that edit beans

Imagine the following use case:

A page to register a new user. I have a User class so i'm all set.
The page class looks something like:

@Meta("tapestry.persistence-strategy=flash") // because of the
validation tracker thing
public class Register {
@Persist
private User _user = new User();

public User getUser() {
        return _user;
    }

    public void setUser(User user) {
        _user = user;
    }
}


I'm not using the BeanEditForm component so my template just has a
couple of TextField components with it's value binded to the user bean
properties.
So, now the problem. Because of the way property persistence works, the
actual reference to the user property is kept, so instead of the
property being reset to a brand new instance it's given the kept reference.
This means that every time that i navigate to the register page the form
will have the values from the last time the form was submitted.

I guess a workaround would be on every place where i navigate to this
page, to reset the user property before navigating to it. This isn't a
very good solution design wise and doesn't solve the problem when
someone accesses the page directly from it's url.

So, how are you guys implementing such use case ?

Thanks

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


Re: T5: FormInjector example

Posted by Shing Hing Man <ma...@yahoo.com>.
Have you looked  at the example 
org.apache.tapestry.integration.app1.pages.
FormInjectorDemo

in the latest Tapestry 5 distribution.
SubmitNotifier combines with FormInjector is 
awesome!

The following wiki on how to look up examples in the
source coce is useful.

http://wiki.apache.org/tapestry/Tapestry5CheckOutTheSourceCode

Shing


--- "Zheng, Xiahong" <Xi...@FMR.COM> wrote:

> Can somebody post an example how to use this
> component? 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail:
> users-help@tapestry.apache.org
> 
> 


Home page : http://www.lombok.demon.co.uk/



      ___________________________________________________________ 
Yahoo! For Good helps you make a difference  

http://uk.promotions.yahoo.com/forgood/

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


T5: FormInjector example

Posted by "Zheng, Xiahong" <Xi...@FMR.COM>.
Can somebody post an example how to use this component? 

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


Re: T5: Strategy for pages that edit beans

Posted by Petros Petrou <pe...@cypoz.com>.
Hugo, 

Your UserPage.tml/UserPage.java is the view and your User POJO the model,
right ?
The way I see the probem is who ever (eg UserListPage, Register Link) needs
to use the UserPage needs to pass in te POJO, otherwise the UserPage wont
know what to display.

What are the UseCases that you need to navigate to the UserPage
1. Register a new User (Use ActionLink and set a "new User()" in the
onActionFromRegisterUser() method)
2. View an existing User (Use ActionLink and set the User in the
onActionFromViewUser() method)
3. Edit an existing User (Use ActionLink and set the User in the
onActionFromEditUser() method)

You can also do all the above by passing the userId in the context of the
ActionLink and then retrieve him from the persistency layer in the
onActivate() method of your UserPage. 

The question I have is, why would you want to reset the User if you are
going to be setting a new one or an existing one anyway ?

Petros


HugoPalma wrote:
> 
> Imagine the following use case:
> 
> A page to register a new user. I have a User class so i'm all set.
> The page class looks something like:
> 
> @Meta("tapestry.persistence-strategy=flash") // because of the
> validation tracker thing
> public class Register {
> @Persist
> private User _user = new User();
> 
> public User getUser() {
>         return _user;
>     }
> 
>     public void setUser(User user) {
>         _user = user;
>     }
> }
> 
> 
> I'm not using the BeanEditForm component so my template just has a
> couple of TextField components with it's value binded to the user bean
> properties.
> So, now the problem. Because of the way property persistence works, the
> actual reference to the user property is kept, so instead of the
> property being reset to a brand new instance it's given the kept
> reference.
> This means that every time that i navigate to the register page the form
> will have the values from the last time the form was submitted.
> 
> I guess a workaround would be on every place where i navigate to this
> page, to reset the user property before navigating to it. This isn't a
> very good solution design wise and doesn't solve the problem when
> someone accesses the page directly from it's url.
> 
> So, how are you guys implementing such use case ?
> 
> Thanks
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-Strategy-for-pages-that-edit-beans-tp14957154p16476114.html
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


Re: T5: Strategy for pages that edit beans

Posted by Hugo Palma <hu...@gmail.com>.
Cool, i didn't even know about that particular event.
I just found that it's explained in the "Input Validation" section of
the docs.

Just thinking out loud, but wouldn't it be great if all the
notifications a component can send were documented with the component
documentation itself ?
Maybe some javadoc markup could be used to document the notifications in
the component class itself and then the reference doc generator could
pick those up ?


Howard Lewis Ship wrote:
> How about an onPrepare() event handler method to reset the _user field
> to a new User instance?
>
> On Jan 18, 2008 8:44 AM, Hugo Palma <hu...@gmail.com> wrote:
>   
>> Imagine the following use case:
>>
>> A page to register a new user. I have a User class so i'm all set.
>> The page class looks something like:
>>
>> @Meta("tapestry.persistence-strategy=flash") // because of the
>> validation tracker thing
>> public class Register {
>> @Persist
>> private User _user = new User();
>>
>> public User getUser() {
>>         return _user;
>>     }
>>
>>     public void setUser(User user) {
>>         _user = user;
>>     }
>> }
>>
>>
>> I'm not using the BeanEditForm component so my template just has a
>> couple of TextField components with it's value binded to the user bean
>> properties.
>> So, now the problem. Because of the way property persistence works, the
>> actual reference to the user property is kept, so instead of the
>> property being reset to a brand new instance it's given the kept reference.
>> This means that every time that i navigate to the register page the form
>> will have the values from the last time the form was submitted.
>>
>> I guess a workaround would be on every place where i navigate to this
>> page, to reset the user property before navigating to it. This isn't a
>> very good solution design wise and doesn't solve the problem when
>> someone accesses the page directly from it's url.
>>
>> So, how are you guys implementing such use case ?
>>
>> Thanks
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>     
>
>
>
>   

Re: T5: Strategy for pages that edit beans

Posted by samlai <sy...@gmail.com>.
What about calling discardPersistentFieldChanges onCleanupRender?

http://tapestry.apache.org/tapestry5/tapestry-core/guide/persist.html

Clearing Persistent Fields

If you reach a point where you know that all data for a page can be
discarded, you can do exactly that.

The method discardPersistentFieldChanges() of ComponentResources will
discard all persistent fields for the page, regardless of which strategy is
used to store the property. This will not affect the page in memory, but
takes effect for subsequent requests.
-- 
View this message in context: http://www.nabble.com/T5%3A-Strategy-for-pages-that-edit-beans-tp14957154p16467529.html
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


Re: T5: Strategy for pages that edit beans

Posted by Josh Canfield <jo...@thedailytube.com>.
On Thu, Apr 3, 2008 at 5:28 AM, Andy Blower <an...@proquest.co.uk> wrote:
>
> I have encountered a similar issue, and the use of onPrepare() doesn't make
> sense to me. Surely there's no point persisting any fields and then
> resetting in onPrepare() is there? May as well just remove the @Persist.
>
> There must be something I'm missing here.. can anyone fill me in?

I believe the issue in this case isn't the @Persist so much as the
initialization of the user object in the page.
private User _user = new User(); <-- Default object for when the page loads

Your pages are pooled so when your page is pulled from the page pool
(or when it's put back I don't recall) it initializes all of it's
properties using the defaults that you set when the object was
constructed. You can make changes to those references, but when the
page loads up again they will be reset. When you initialize a page
property with an object that is used in a form, the properties of that
object are going to be updated when the form is submitted. The next
time that page object is pulled from the pool it's going to get that
modified User object and it's pre-populated values. @Persist limits
the objects storage to the session (or client or whatever extension
you've created) but the class property initialization will be shared
across all your sessions.

Try breaking into your debugger in the getUser() method and checking
out your page object. It has a bunch of fields added to it, including
_$user_default.

Whether or not you need to @Persist the User at all is another
question entirely... I much prefer to initialize the user from the
database on each page load and use the onPassivate event to get the
stored id into the context.

Hopefully some of that is intelligible...
Josh

>
>
>
> Howard Lewis Ship wrote:
> >
> > How about an onPrepare() event handler method to reset the _user field
> > to a new User instance?
> >
> > On Jan 18, 2008 8:44 AM, Hugo Palma <hu...@gmail.com> wrote:
> >> Imagine the following use case:
> >>
> >> A page to register a new user. I have a User class so i'm all set.
> >> The page class looks something like:
> >>
> >> @Meta("tapestry.persistence-strategy=flash") // because of the
> >> validation tracker thing
> >> public class Register {
> >> @Persist
> >> private User _user = new User();
> >>
> >> public User getUser() {
> >>         return _user;
> >>     }
> >>
> >>     public void setUser(User user) {
> >>         _user = user;
> >>     }
> >> }
> >>
> >>
> >> I'm not using the BeanEditForm component so my template just has a
> >> couple of TextField components with it's value binded to the user bean
> >> properties.
> >> So, now the problem. Because of the way property persistence works, the
> >> actual reference to the user property is kept, so instead of the
> >> property being reset to a brand new instance it's given the kept
> >> reference.
> >> This means that every time that i navigate to the register page the form
> >> will have the values from the last time the form was submitted.
> >>
> >> I guess a workaround would be on every place where i navigate to this
> >> page, to reset the user property before navigating to it. This isn't a
> >> very good solution design wise and doesn't solve the problem when
> >> someone accesses the page directly from it's url.
> >>
> >> So, how are you guys implementing such use case ?
> >>
> >> Thanks
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
> >
> > --
> > Howard M. Lewis Ship
> >
> > Creator Apache Tapestry and Apache HiveMind
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/T5%3A-Strategy-for-pages-that-edit-beans-tp14957154p16467445.html
> 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
>
>



-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

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


Re: T5: Strategy for pages that edit beans

Posted by Andy Blower <an...@proquest.co.uk>.
I have encountered a similar issue, and the use of onPrepare() doesn't make
sense to me. Surely there's no point persisting any fields and then
resetting in onPrepare() is there? May as well just remove the @Persist.

There must be something I'm missing here.. can anyone fill me in?


Howard Lewis Ship wrote:
> 
> How about an onPrepare() event handler method to reset the _user field
> to a new User instance?
> 
> On Jan 18, 2008 8:44 AM, Hugo Palma <hu...@gmail.com> wrote:
>> Imagine the following use case:
>>
>> A page to register a new user. I have a User class so i'm all set.
>> The page class looks something like:
>>
>> @Meta("tapestry.persistence-strategy=flash") // because of the
>> validation tracker thing
>> public class Register {
>> @Persist
>> private User _user = new User();
>>
>> public User getUser() {
>>         return _user;
>>     }
>>
>>     public void setUser(User user) {
>>         _user = user;
>>     }
>> }
>>
>>
>> I'm not using the BeanEditForm component so my template just has a
>> couple of TextField components with it's value binded to the user bean
>> properties.
>> So, now the problem. Because of the way property persistence works, the
>> actual reference to the user property is kept, so instead of the
>> property being reset to a brand new instance it's given the kept
>> reference.
>> This means that every time that i navigate to the register page the form
>> will have the values from the last time the form was submitted.
>>
>> I guess a workaround would be on every place where i navigate to this
>> page, to reset the user property before navigating to it. This isn't a
>> very good solution design wise and doesn't solve the problem when
>> someone accesses the page directly from it's url.
>>
>> So, how are you guys implementing such use case ?
>>
>> Thanks
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 
> 
> -- 
> Howard M. Lewis Ship
> 
> Creator Apache Tapestry and Apache HiveMind
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-Strategy-for-pages-that-edit-beans-tp14957154p16467445.html
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


Re: T5: Strategy for pages that edit beans

Posted by Howard Lewis Ship <hl...@gmail.com>.
How about an onPrepare() event handler method to reset the _user field
to a new User instance?

On Jan 18, 2008 8:44 AM, Hugo Palma <hu...@gmail.com> wrote:
> Imagine the following use case:
>
> A page to register a new user. I have a User class so i'm all set.
> The page class looks something like:
>
> @Meta("tapestry.persistence-strategy=flash") // because of the
> validation tracker thing
> public class Register {
> @Persist
> private User _user = new User();
>
> public User getUser() {
>         return _user;
>     }
>
>     public void setUser(User user) {
>         _user = user;
>     }
> }
>
>
> I'm not using the BeanEditForm component so my template just has a
> couple of TextField components with it's value binded to the user bean
> properties.
> So, now the problem. Because of the way property persistence works, the
> actual reference to the user property is kept, so instead of the
> property being reset to a brand new instance it's given the kept reference.
> This means that every time that i navigate to the register page the form
> will have the values from the last time the form was submitted.
>
> I guess a workaround would be on every place where i navigate to this
> page, to reset the user property before navigating to it. This isn't a
> very good solution design wise and doesn't solve the problem when
> someone accesses the page directly from it's url.
>
> So, how are you guys implementing such use case ?
>
> Thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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