You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris <ch...@gmx.at> on 2015/04/22 03:48:17 UTC

Storing data in wicket session

Hi all,

I need so share a list of strings between some objects during a session; Within the session, the list of strings will be deleted based on specific requests.

Currently, I store them in the page but the disadvantage of this approach is that I have to delegate the list to each sub(sub)component.

Would it be good practice to store this directly in the wicket session? How to do this?

A second approach would be to store it in the user object and inject this object in the individual components.

Could you give me a recommendation?

Thanks, Chris


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


Re: Storing data in wicket session

Posted by Chris <ch...@gmx.at>.
Martin, thanks a lot for your explanations!

Chris


> Am 22.04.2015 um 08:05 schrieb Martin Grigorov <mg...@apache.org>:
> 
> Hi,
> 
> On Wed, Apr 22, 2015 at 4:48 AM, Chris <ch...@gmx.at> wrote:
> 
>> Hi all,
>> 
>> I need so share a list of strings between some objects during a session;
>> Within the session, the list of strings will be deleted based on specific
>> requests.
>> 
>> Currently, I store them in the page but the disadvantage of this approach
>> is that I have to delegate the list to each sub(sub)component.
>> 
> 
> You can create a helper class: PageHelper#getMyList(Page page) { return
> ((MyPage) page).getMyList();}
> And use it in any component: MyList myList =
> PageHelper.getMyList(getPage());
> 
> 
>> 
>> Would it be good practice to store this directly in the wicket session?
>> How to do this?
>> 
> 
> Yes. Just create a property/getter/setter in MySession and then use it:
> ((MySession) Session.get()).getMyList();
> Make sure you synchronize the access to the list!
> 
> 
>> 
>> A second approach would be to store it in the user object and inject this
>> object in the individual components.
>> 
> 
> This is also an option. It could be a session scoped bean, or a provider...
> 
> 
>> 
>> Could you give me a recommendation?
>> 
>> Thanks, Chris
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 


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


Re: Storing data in wicket session

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Wed, Apr 22, 2015 at 4:48 AM, Chris <ch...@gmx.at> wrote:

> Hi all,
>
> I need so share a list of strings between some objects during a session;
> Within the session, the list of strings will be deleted based on specific
> requests.
>
> Currently, I store them in the page but the disadvantage of this approach
> is that I have to delegate the list to each sub(sub)component.
>

You can create a helper class: PageHelper#getMyList(Page page) { return
((MyPage) page).getMyList();}
And use it in any component: MyList myList =
PageHelper.getMyList(getPage());


>
> Would it be good practice to store this directly in the wicket session?
> How to do this?
>

Yes. Just create a property/getter/setter in MySession and then use it:
((MySession) Session.get()).getMyList();
Make sure you synchronize the access to the list!


>
> A second approach would be to store it in the user object and inject this
> object in the individual components.
>

This is also an option. It could be a session scoped bean, or a provider...


>
> Could you give me a recommendation?
>
> Thanks, Chris
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>