You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Hilco Wijbenga <hi...@gmail.com> on 2010/01/21 02:50:47 UTC

How to clear an @Persist-ed value in a component?

Hi all,

I have a page (MyPage) with an embedded component (MyComponent). The
component uses @Persist to store a value (@Persist String myValue;).

This all works (of course). But I noticed that when I jump from
domain.com/index to domain.com/mypage, myValue still has the value
from last time. How do I clear it?

I tried to use @Inject MyComponent myComponent in MyPage so that I
could clear myValue in the pageDetached method but apparently it's not
possible to inject a component?

Any advice would be appreciated (also comments about this approach, is
it wrong to @Persist values in a component?).

Cheers,
Hilco

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


Re: How to clear an @Persist-ed value in a component?

Posted by Hilco Wijbenga <hi...@gmail.com>.
2010/1/21 Howard Lewis Ship <hl...@gmail.com>:
> In Tapestry 5.2, there's a new lifecycle method, pageReset(), that
> your pages/components can implement.  It is invoked during page render
> requests, when the active page changes. See the nightly documentation
> for details.

That sounds very useful. I'll have a look at that once 5.2 is out.

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


Re: How to clear an @Persist-ed value in a component?

Posted by Howard Lewis Ship <hl...@gmail.com>.
ComponentResources includes a method, discardPersistentFieldChanges(),
for this purpose ... the trick is to know when to invoke it.

In Tapestry 5.2, there's a new lifecycle method, pageReset(), that
your pages/components can implement.  It is invoked during page render
requests, when the active page changes. See the nightly documentation
for details.

On Wed, Jan 20, 2010 at 5:50 PM, Hilco Wijbenga
<hi...@gmail.com> wrote:
> Hi all,
>
> I have a page (MyPage) with an embedded component (MyComponent). The
> component uses @Persist to store a value (@Persist String myValue;).
>
> This all works (of course). But I noticed that when I jump from
> domain.com/index to domain.com/mypage, myValue still has the value
> from last time. How do I clear it?
>
> I tried to use @Inject MyComponent myComponent in MyPage so that I
> could clear myValue in the pageDetached method but apparently it's not
> possible to inject a component?
>
> Any advice would be appreciated (also comments about this approach, is
> it wrong to @Persist values in a component?).
>
> Cheers,
> Hilco
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: How to clear an @Persist-ed value in a component?

Posted by Hilco Wijbenga <hi...@gmail.com>.
2010/1/21 Stephan Windmüller <st...@cs.tu-dortmund.de>:
> Am 21.01.2010 09:04, Hilco Wijbenga wrote:
>
>> So how would you suggest I store data that I only need in a component?
>
> That depends on what you want to do with the data and where you need it.

The component would consist of a dynamic set of radiogroups and
checkboxes. While the user just sets up his choices I wanted to let
the component take care of remembering those choices (as this is all
temporary and the page doesn't need to know about it). Once completely
done a separate submit would yield an object (for the page) based on
those choices and the component would be done.

>> I'm already using the activation context (not for this component) but
>> the component has a fair number of fields and this is only the first
>> component. I'm afraid I would be overloading the activation context.
>> (It's not a lot of data, just a lot of fields.)
>
> Perhaps you could describe what sort of component this is, what the users
> does with it and what you do with the data.

See above.

>> I'm not using a database so all data needs to be in either the
>> session, the URL, or in (the server's) memory (other than the
>> session).
>
> So you want to store all the data which the user generates in his session?

:-) I guess there's not really another option. I may be making things
too complicated.

>> What would be the most economical and scalable way to store
>>
>> up to a few hundred small fields (tiny integers and single characters
>> only)? I could probably work out a way to compress it all into a
>> single string which I could store in the activation context.
>
> On one page I use an approach like this. I want the user to be able to undo
> the settings until he leaves the page, so I store all previous steps in a
> Java List, convert it to compressed XML and store it in a hidden field. This
> is rather ugly but the only way I could think of.

Yes, exactly.

Cheers,
Hilco

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


Re: How to clear an @Persist-ed value in a component?

Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
Am 21.01.2010 09:04, Hilco Wijbenga wrote:

> So how would you suggest I store data that I only need in a component?

That depends on what you want to do with the data and where you need it.

> I'm already using the activation context (not for this component) but
> the component has a fair number of fields and this is only the first
> component. I'm afraid I would be overloading the activation context.
> (It's not a lot of data, just a lot of fields.)

Perhaps you could describe what sort of component this is, what the 
users does with it and what you do with the data.

> I'm not using a database so all data needs to be in either the
> session, the URL, or in (the server's) memory (other than the
> session).

So you want to store all the data which the user generates in his session?

 > What would be the most economical and scalable way to store
> up to a few hundred small fields (tiny integers and single characters
> only)? I could probably work out a way to compress it all into a
> single string which I could store in the activation context.

On one page I use an approach like this. I want the user to be able to 
undo the settings until he leaves the page, so I store all previous 
steps in a Java List, convert it to compressed XML and store it in a 
hidden field. This is rather ugly but the only way I could think of.

- Stephan

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


Re: How to clear an @Persist-ed value in a component?

Posted by Hilco Wijbenga <hi...@gmail.com>.
2010/1/20 Stephan Windmüller <st...@cs.tu-dortmund.de>:
> Hilco Wijbenga wrote:
>
>> Any advice would be appreciated (also comments about this approach, is
>> it wrong to @Persist values in a component?).
>
> You should use @Persist only when it is absolutely necessary. When you
> only need it on one page this may be an indicator to use another
> solution. What happens to your page is someone uses browser tabs?
>
> Would the activation context do what you need?

So how would you suggest I store data that I only need in a component?
I'm already using the activation context (not for this component) but
the component has a fair number of fields and this is only the first
component. I'm afraid I would be overloading the activation context.
(It's not a lot of data, just a lot of fields.)

I'm not using a database so all data needs to be in either the
session, the URL, or in (the server's) memory (other than the
session). What would be the most economical and scalable way to store
up to a few hundred small fields (tiny integers and single characters
only)? I could probably work out a way to compress it all into a
single string which I could store in the activation context. I suppose
this is the same as the "client" strategy for @Persist? This is warned
against as being expensive and not scalable.

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


Re: How to clear an @Persist-ed value in a component?

Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
Hilco Wijbenga wrote:

> Any advice would be appreciated (also comments about this approach, is
> it wrong to @Persist values in a component?).

You should use @Persist only when it is absolutely necessary. When you
only need it on one page this may be an indicator to use another
solution. What happens to your page is someone uses browser tabs?

Would the activation context do what you need?

- Stephan

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


Re: How to clear an @Persist-ed value in a component?

Posted by Hilco Wijbenga <hi...@gmail.com>.
2010/1/20 Robert Zeigler <ro...@scazdl.org>:
> 1) @InjectComponent to inject a component instance that is specified in the
> template.

Ah, it's in a different package. Perfect, this works.

> 2) Check out:
> http://tapestry.apache.org/tapestry5/guide/persist.html
> See the section under the heading:
> Clearing Persistent Fields

Yep, I got that working too now.

Thanks!

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


Re: How to clear an @Persist-ed value in a component?

Posted by Robert Zeigler <ro...@scazdl.org>.
1) @InjectComponent to inject a component instance that is specified  
in the template.
2) Check out:
http://tapestry.apache.org/tapestry5/guide/persist.html
See the section under the heading:
Clearing Persistent Fields

Cheers,

Robert

On Jan 20, 2010, at 1/207:50 PM , Hilco Wijbenga wrote:

> Hi all,
>
> I have a page (MyPage) with an embedded component (MyComponent). The
> component uses @Persist to store a value (@Persist String myValue;).
>
> This all works (of course). But I noticed that when I jump from
> domain.com/index to domain.com/mypage, myValue still has the value
> from last time. How do I clear it?
>
> I tried to use @Inject MyComponent myComponent in MyPage so that I
> could clear myValue in the pageDetached method but apparently it's not
> possible to inject a component?
>
> Any advice would be appreciated (also comments about this approach, is
> it wrong to @Persist values in a component?).
>
> Cheers,
> Hilco
>
> ---------------------------------------------------------------------
> 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