Here is what eventually seemed to work. Is there a better way to do it?
I added @Persist to the item declaration:
@Persist
@Property
Item item;
If there isn't an item, I create one in onActivate.
public void onActivate() {
if(item == null) item = new Item();
}
If everything is successful I call
componentResources.discardPersistentFieldChanges();
Right before I return the next page. (I'm not sure if I need to do that or not.)
Thanks!
Jack
-----Original Message-----
From: [email protected]
Sent: Friday, February 4, 2011 3:53pm
To: "Tapestry users" <[email protected]>
Subject: Re: Object is sticking around between sessions.
Ok I tried putting the
void onActivate() {
item = new Item();
}
But now Ajax is acting funny. Is onActivate called every time an Ajax response
is requested?
Jack
-----Original Message-----
From: "Thiago H. de Paula Figueiredo" <[email protected]>
Sent: Friday, February 4, 2011 3:46pm
To: "Tapestry users" <[email protected]>, [email protected]
Subject: Re: Object is sticking around between sessions.
On Fri, 04 Feb 2011 18:31:53 -0200, <[email protected]> wrote:
> Two things that might have a bearing on this:
> 1. I am creating a new item that backs the form in the page .java file
> at its declaration. So Item item = new Item();
Never initialize a field in its declaration unless it is an atomic value.
That's the source of your problem. After the request is finished, all
fields are reset to their initial declared values. As Item is a class,
your item fields is always pointing to the same object. Use the prepare
event or onActivate() instead.
By the way, use the validate form event to do validation instead of submit.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]