No need to persist. The form holds the person's data, and submits it, and since
you are doing Ajax calls there is no redirect - it goes VALIDATE, SUCCESS,
PREPARE_FOR_RENDER, PREPARE all in the same request - so the person data is
still available in onPrepareForRender and goes round trip back out to the form.
If you're doing create and update with the same page, try (untested code):
private boolean inited;
void onPrepareForRender() {
if (!inited) {
if (person.getId() == null) {
// set up empty person initial data
}
else {
// Get person for the form fields to overlay
person = personService.findPerson(person);
}
inited = true;
}
}
void onPrepareForSubmit() {
if (person.getId() != null) {
// Get person for the form fields to overlay
person = personService.findPerson(person);
}
}
On 06/05/2012, at 12:40 PM, netdawg wrote:
> Yep, second Geoff. That is what I am doing - using onPrepareForRender().
>
> Say specialized form is EditPerson.tml
>
> <form t:type="Form" t:id="person" >
> <t:errors />
>
> [various form elements]
>
> </form>
> </html>
>
> In the corresponding EditPerson.java, this what I have:
>
> /**
> * Enables reuse of Edit as Create
> */
> void onPrepareForRender()
> {
> if (this.person == null)
> {
> this.person = new Person(); // Person with defaults - populates the
> form
> }
> else
> {
> // nothing to do - form will pick up persisted person object
> }
> }
>
> I am posting because this probably most directly addresses your question -
> initialize with default values(?) Not sure if it is the most correct or
> elegant or what the side effects are - good or bad. One being that the
> person object needs to be persisted in the Session (for submit to work).
> Whereas using the beaneditor & co, you just need to use activationContext
> and the person is initialized by just the Id.
>
> Thoughts?
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Best-place-to-initialize-form-data-tp5685603p5688725.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]