You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Matías Blasi <ma...@gmail.com> on 2012/07/26 15:10:38 UTC

Shared @SessionState???

Hi all,

I'm facing the following issue:

I have a @SessionState object for a custom type.

As far as I understand that would be handled individually for each "user
session", but I am seeing that the value is shared across all my user
sessions... It shouldn't be possible, in fact, if it works like that we
couldn't implement a shopping cart with this mechanism.... and I had a
shopping cart working fine in my application!

Do you imagine what could be wrong to get this behaiviour? I cant imagine
how implement a cross-SessionState without external persistence...

Here is my code:

public class CalificadosMessagesServiceImpl implements
CalificadosMessagesService {

@SessionState(create=true)
private CalificadosMessagesBag messagesBag;
...
...

@Override
public List<CalificadosMessage> getSessoinMessages() {
return this.messagesBag.getMessages();
}

@Override
public void recordSessionMessage(CalificadosMessage message) {
this.messagesBag.addMessage(message);
}
...
...
}

All the logged users (from different browsers), get the same messages!

Am I loosing something obvious?


Regards,
Matias.

Re: Shared @SessionState???

Posted by Taha Siddiqi <ta...@gmail.com>.
Hi Matias

@SessionState works for pages/mixins/components and not for service injection. If you want to use session object in a service, you can use ApplicationStateManager(get and set)

regards
Taha


On Jul 26, 2012, at 6:40 PM, Matías Blasi wrote:

> Hi all,
> 
> I'm facing the following issue:
> 
> I have a @SessionState object for a custom type.
> 
> As far as I understand that would be handled individually for each "user
> session", but I am seeing that the value is shared across all my user
> sessions... It shouldn't be possible, in fact, if it works like that we
> couldn't implement a shopping cart with this mechanism.... and I had a
> shopping cart working fine in my application!
> 
> Do you imagine what could be wrong to get this behaiviour? I cant imagine
> how implement a cross-SessionState without external persistence...
> 
> Here is my code:
> 
> public class CalificadosMessagesServiceImpl implements
> CalificadosMessagesService {
> 
> @SessionState(create=true)
> private CalificadosMessagesBag messagesBag;
> ...
> ...
> 
> @Override
> public List<CalificadosMessage> getSessoinMessages() {
> return this.messagesBag.getMessages();
> }
> 
> @Override
> public void recordSessionMessage(CalificadosMessage message) {
> this.messagesBag.addMessage(message);
> }
> ...
> ...
> }
> 
> All the logged users (from different browsers), get the same messages!
> 
> Am I loosing something obvious?
> 
> 
> Regards,
> Matias.


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


Re: Shared @SessionState???

Posted by Christian Riedel <cr...@googlemail.com>.
Hi,

A service is a singleton by default. If you store a session-state object as a singleton service's member, every user will see the session state of the user who triggered your service for the first time.
Either change your service to PerThread scope [1] or better yet inject your session state object only in pages/components/mixins. Members of components are always per thread scoped.

[1] http://tapestry.apache.org/defining-tapestry-ioc-services.html


Cheers,
Christian


Am 26.07.2012 um 15:10 schrieb Matías Blasi:

> Hi all,
> 
> I'm facing the following issue:
> 
> I have a @SessionState object for a custom type.
> 
> As far as I understand that would be handled individually for each "user
> session", but I am seeing that the value is shared across all my user
> sessions... It shouldn't be possible, in fact, if it works like that we
> couldn't implement a shopping cart with this mechanism.... and I had a
> shopping cart working fine in my application!
> 
> Do you imagine what could be wrong to get this behaiviour? I cant imagine
> how implement a cross-SessionState without external persistence...
> 
> Here is my code:
> 
> public class CalificadosMessagesServiceImpl implements
> CalificadosMessagesService {
> 
> @SessionState(create=true)
> private CalificadosMessagesBag messagesBag;
> ...
> ...
> 
> @Override
> public List<CalificadosMessage> getSessoinMessages() {
> return this.messagesBag.getMessages();
> }
> 
> @Override
> public void recordSessionMessage(CalificadosMessage message) {
> this.messagesBag.addMessage(message);
> }
> ...
> ...
> }
> 
> All the logged users (from different browsers), get the same messages!
> 
> Am I loosing something obvious?
> 
> 
> Regards,
> Matias.


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


Re: Shared @SessionState???

Posted by Taha Siddiqi <ta...@gmail.com>.
If you are using applicationStateManager then I don't think you need PerThread service


On Jul 26, 2012, at 9:41 PM, Matías Blasi wrote:

> Thank all of you!
> 
> That was the problem.
> It worked by asking for my SessionState object to the
> AplicationStateManager and setting my service as Threaded.
> 
> Thank you very much.
> 
> Regards!
> Matias.
> 
> 
> On Thu, Jul 26, 2012 at 10:10 AM, Matías Blasi <ma...@gmail.com>wrote:
> 
>> Hi all,
>> 
>> I'm facing the following issue:
>> 
>> I have a @SessionState object for a custom type.
>> 
>> As far as I understand that would be handled individually for each "user
>> session", but I am seeing that the value is shared across all my user
>> sessions... It shouldn't be possible, in fact, if it works like that we
>> couldn't implement a shopping cart with this mechanism.... and I had a
>> shopping cart working fine in my application!
>> 
>> Do you imagine what could be wrong to get this behaiviour? I cant imagine
>> how implement a cross-SessionState without external persistence...
>> 
>> Here is my code:
>> 
>> public class CalificadosMessagesServiceImpl implements
>> CalificadosMessagesService {
>> 
>> @SessionState(create=true)
>> private CalificadosMessagesBag messagesBag;
>> ...
>> ...
>> 
>> @Override
>> public List<CalificadosMessage> getSessoinMessages() {
>> return this.messagesBag.getMessages();
>> }
>> 
>> @Override
>> public void recordSessionMessage(CalificadosMessage message) {
>> this.messagesBag.addMessage(message);
>> }
>> ...
>> ...
>> }
>> 
>> All the logged users (from different browsers), get the same messages!
>> 
>> Am I loosing something obvious?
>> 
>> 
>> Regards,
>> Matias.
>> 


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


Re: Shared @SessionState???

Posted by Matías Blasi <ma...@gmail.com>.
Thank all of you!

That was the problem.
It worked by asking for my SessionState object to the
AplicationStateManager and setting my service as Threaded.

Thank you very much.

Regards!
Matias.


On Thu, Jul 26, 2012 at 10:10 AM, Matías Blasi <ma...@gmail.com>wrote:

> Hi all,
>
> I'm facing the following issue:
>
> I have a @SessionState object for a custom type.
>
> As far as I understand that would be handled individually for each "user
> session", but I am seeing that the value is shared across all my user
> sessions... It shouldn't be possible, in fact, if it works like that we
> couldn't implement a shopping cart with this mechanism.... and I had a
> shopping cart working fine in my application!
>
> Do you imagine what could be wrong to get this behaiviour? I cant imagine
> how implement a cross-SessionState without external persistence...
>
> Here is my code:
>
> public class CalificadosMessagesServiceImpl implements
> CalificadosMessagesService {
>
> @SessionState(create=true)
> private CalificadosMessagesBag messagesBag;
> ...
> ...
>
> @Override
> public List<CalificadosMessage> getSessoinMessages() {
>  return this.messagesBag.getMessages();
> }
>
> @Override
>  public void recordSessionMessage(CalificadosMessage message) {
> this.messagesBag.addMessage(message);
>  }
> ...
> ...
> }
>
> All the logged users (from different browsers), get the same messages!
>
> Am I loosing something obvious?
>
>
> Regards,
> Matias.
>