You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by es...@cumego.com on 2009/06/19 16:09:55 UTC

T4.1: remove ASO from session

Hi!
I'm using Tapestry 4.1.
How to remove previously created ASO from session, so that @InjectStateFlag
could return false again?

Sample code (assume that ASO "foo" is already set, so the flag returns
TRUE):

@InjectState("foo")
public abstract Long getFooId();
public abstract void setFooId(Long id);

@InjectStateFlag("foo")
public abstract boolean isFooSelected();

// used in form by property selection model with an empty option
public abstract Long getSelectedFooId();
public abstract void setSelectedFooId(Long id);

// called on submit
public void changeFoo() {
//HERE: how to remove ASO when getSelectedFoo() is null?
setFooId(getSelectedFooId()); // setFooId(null) doesn't change flag
}

Is there a way to do this? Or maybe there is another approach to manage
state across pages?
Of course, i don't want to invalidate session. :-)

Best regards,
Przemysław Wojnowski

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


Re: T4.1: remove ASO from session

Posted by Przemysław Wojnowski <es...@cumego.com>.
Thanks for response.
I've added issue: https://issues.apache.org/jira/browse/TAPESTRY-2740

Your workaround works. Thanks!

--- workaround ---
@InjectObject("service:tapestry.state.SessionScopeManager")
public abstract StateObjectPersistenceManager getStateManager();

public void someMethod() {
    if (getStateManager().exists("foo")) {
        // ASO is in the session
    } else {
        // ASO was removed
   }
}
---

Regards,
Przemysław Wojnowski

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


Re: T4.1: remove ASO from session

Posted by Andreas Andreou <an...@di.uoa.gr>.
I forgot that calling getFooId() will create the "foo" ASO
and so the workaround will never work...

I guess you could inject SessionScopeManager and call
sessionScopeManager.exists("foo") for another workaround

2009/6/21 Andreas Andreou <an...@di.uoa.gr>:
> Setting fooId to null DOES remove the object from session, but
> judging from the sources of ApplicationStateManagerImpl (its
> _stateObjects never removes items),
> the stateFlag will continue to return true...
>
> This happens 'cause the map that holdes the ASOs still has the
> "foo" key (that now points to null)
>
> So, the workaround seems to be to add
> boolean isFooReallySelected() {
> return isFooSelected() && getFooId()!=null; }
>
> You could add an issue about this at
> https://issues.apache.org/jira/browse/TAPESTRY,
> https://issues.apache.org/jira/browse/TAPESTRY-912 looks related
>
> On Fri, Jun 19, 2009 at 5:09 PM, <es...@cumego.com> wrote:
>> Hi!
>> I'm using Tapestry 4.1.
>> How to remove previously created ASO from session, so that @InjectStateFlag
>> could return false again?
>>
>> Sample code (assume that ASO "foo" is already set, so the flag returns
>> TRUE):
>>
>> @InjectState("foo")
>> public abstract Long getFooId();
>> public abstract void setFooId(Long id);
>>
>> @InjectStateFlag("foo")
>> public abstract boolean isFooSelected();
>>
>> // used in form by property selection model with an empty option
>> public abstract Long getSelectedFooId();
>> public abstract void setSelectedFooId(Long id);
>>
>> // called on submit
>> public void changeFoo() {
>> //HERE: how to remove ASO when getSelectedFoo() is null?
>> setFooId(getSelectedFooId()); // setFooId(null) doesn't change flag
>> }
>>
>> Is there a way to do this? Or maybe there is another approach to manage
>> state across pages?
>> Of course, i don't want to invalidate session. :-)
>>
>> Best regards,
>> Przemysław Wojnowski
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
>
> --
> Andreas Andreou - andyhot@apache.org - http://blog.andyhot.gr
> Tapestry / Tacos developer
> Open Source / JEE Consulting
>



-- 
Andreas Andreou - andyhot@apache.org - http://blog.andyhot.gr
Tapestry / Tacos developer
Open Source / JEE Consulting

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


Re: T4.1: remove ASO from session

Posted by Andreas Andreou <an...@di.uoa.gr>.
Setting fooId to null DOES remove the object from session, but
judging from the sources of ApplicationStateManagerImpl (its
_stateObjects never removes items),
the stateFlag will continue to return true...

This happens 'cause the map that holdes the ASOs still has the
"foo" key (that now points to null)

So, the workaround seems to be to add
boolean isFooReallySelected() {
return isFooSelected() && getFooId()!=null; }

You could add an issue about this at
https://issues.apache.org/jira/browse/TAPESTRY,
https://issues.apache.org/jira/browse/TAPESTRY-912 looks related

On Fri, Jun 19, 2009 at 5:09 PM, <es...@cumego.com> wrote:
> Hi!
> I'm using Tapestry 4.1.
> How to remove previously created ASO from session, so that @InjectStateFlag
> could return false again?
>
> Sample code (assume that ASO "foo" is already set, so the flag returns
> TRUE):
>
> @InjectState("foo")
> public abstract Long getFooId();
> public abstract void setFooId(Long id);
>
> @InjectStateFlag("foo")
> public abstract boolean isFooSelected();
>
> // used in form by property selection model with an empty option
> public abstract Long getSelectedFooId();
> public abstract void setSelectedFooId(Long id);
>
> // called on submit
> public void changeFoo() {
> //HERE: how to remove ASO when getSelectedFoo() is null?
> setFooId(getSelectedFooId()); // setFooId(null) doesn't change flag
> }
>
> Is there a way to do this? Or maybe there is another approach to manage
> state across pages?
> Of course, i don't want to invalidate session. :-)
>
> Best regards,
> Przemysław Wojnowski
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Andreas Andreou - andyhot@apache.org - http://blog.andyhot.gr
Tapestry / Tacos developer
Open Source / JEE Consulting

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