You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ben Sommerville <be...@bulletproof.com.au> on 2007/06/01 02:49:28 UTC

RE: T5: when is @Persist necessary and when not...

The default value that the _person member gets reset to will be 
the Person _instance_ that you assigned in the constructor.

So when the form is submitted that instance will have its members
set based on the form values.  When the page is rendered the 
same instance will be used as the default value & you will see
your submitted values.

Basically default values only work properly when they are immutable.
e.g. strings, 

For a form I'd say the best place to create those compound objects
is in the onPrepare method.  This will be invoked before any processing/
rendering occurs.  (see the Form component subsection of 
http://tapestry.apache.org/tapestry5/tapestry-core/guide/validation.html)

Another option is the pageAttached method (invoked when page
is attached to the request) which is documented at
http://tapestry.apache.org/tapestry5/tapestry-core/guide/lifecycle.html

cheers,
Ben


> 
> This is strange. If the _person member variable gets reset to
> the default at the end of each request I would expect not to
> see the values from it on my page after submit in the render
> request.
> 
> What I want to achieve is very much the same scenario found in
> the documentation section "Form Input and Validation", only I
> have several compound objects like `Person'. Since the form
> accesses members of these objects they need to be created in
> the page class. Since the constructor is obviously not the
> right place for this, which one would you suggest?
> 
> Cheers,
> 
> Martin
> 
> -- 
> ----------- / http://herbert.the-little-red-haired-girl.org / 
> -------------
> =+= 
> Was ist ein Cluster?
> Wenn vier Bratscher unisono spielen.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 


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


RE: T5: when is @Persist necessary and when not...

Posted by Ben Sommerville <be...@bulletproof.com.au>.
If you initialise the objects in either of those methods then 
you shouldn't need default values anymore.  
i.e no assignment in constructor or field init

Otherwise if you are @Persisting those variables in the page 
(not the compound object) then you values should be retained.

If you are doing all that & it isn't working I think I'd need
to see the code again to be able help any further

cheers,
Ben

> -----Original Message-----
> From: Martin Dietze [mailto:di@mail.fh-wedel.de] On Behalf Of 
> Martin Dietze
> Sent: Friday, 1 June 2007 5:33 PM
> To: 'Tapestry users'
> Subject: Re: T5: when is @Persist necessary and when not...
> 
> On Thu, May 31, 2007, Ben Sommerville wrote:
> 
> > For a form I'd say the best place to create those compound objects
> > is in the onPrepare method.  This will be invoked before 
> any processing/
> > rendering occurs.  (see the Form component subsection of 
> > 
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/valid
> ation.html)
> > 
> > Another option is the pageAttached method (invoked when page
> > is attached to the request) which is documented at
> > 
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/lifec
> ycle.html
> 
> Hmm, having tried both these options this leads to the objects
> being replaced by defaults before the resultpage after a submit
> is created, thus my submit results (the variables are annotated
> with "@Persist") get lost. Or am I misunderstanding something
> completely?
> 
> Cheers,
> 
> Martin
> 
> -- 
> ----------- / http://herbert.the-little-red-haired-girl.org / 
> -------------
> =+= 
> Wie verhindert man, dass einem die Geige gestohlen wird?
> Man legt sie in einen Bratschenkasten...
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 


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


Re: T5: when is @Persist necessary and when not...

Posted by Martin Dietze <di...@fh-wedel.de>.
On Thu, May 31, 2007, Ben Sommerville wrote:

> For a form I'd say the best place to create those compound objects
> is in the onPrepare method.  This will be invoked before any processing/
> rendering occurs.  (see the Form component subsection of 
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/validation.html)
> 
> Another option is the pageAttached method (invoked when page
> is attached to the request) which is documented at
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/lifecycle.html

Hmm, having tried both these options this leads to the objects
being replaced by defaults before the resultpage after a submit
is created, thus my submit results (the variables are annotated
with "@Persist") get lost. Or am I misunderstanding something
completely?

Cheers,

Martin

-- 
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+= 
Wie verhindert man, dass einem die Geige gestohlen wird?
Man legt sie in einen Bratschenkasten...

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