wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthias Keller <matthias.kel...@ergon.ch>
Subject Re: How to clear PageMap in Wicket 1.5?
Date Mon, 14 Nov 2011 11:41:00 GMT
Hi Martin

Sorry for the delay, I was busy with other things recently.
Of course you're right, that clearing all pages, including the NextPage 
isn't a smart thing and I don't wanna do that anyway.
But what I need is away to redirect to a new (non-bookmarkable!) 
NextPage while clearing all other stored page instances.
I'll try to illustrate a flow; the user starts on the homepage  
HomePage. All pages are stateful:
HomePage <click on a link> AnotherPage <click on the special Link we're 
talking about> NextPage.
Now, when the user is on the NextPage of course all links on THAT page 
do have to work as expected. But all previous page instances (of 
HomePage and AnotherPage) must be cleared from the page store, so that 
if the user clicks BACK in his browser (and would go back to 
AnotherPage), a PageExpiredException must be thrown.
I can achieve that with Session.replaceSession() BEFORE calling 
setResponsePage(new NextPage()) - but this method has additional 
semantics (change the session ID) which I may not want to have.
That's why I came to

getSessionStore().invalidate(RequestCycle.get().getRequest());

which *appears* to do what I want but due to the lack of knowledge of 
the session/pagestore internals I cannot say if it's correct or 
sufficient to do that...

So the important bit is, that when calling a usable  Session.clear(), 
the current page shall not be stored in the session/pagestore anymore...

Thanks

Matt

On 2011-11-03 09:05, Martin Grigorov wrote:
> Hi Matthias,
>
> On Thu, Nov 3, 2011 at 9:30 AM, Matthias Keller
> <matthias.keller@ergon.ch>  wrote:
>> Hi Martin
>>
>> I see this is getting in the same direction as it was with Wicket 1.4 - it
>> just doesn't work as expected.
>> The method you propose results in the next page shown as expected and going
>> back is not possible anymore. But so is clicking on anything on the next
>> page then - those links seem to be invalid then too...
>>
>> The problem seems to be in the order of events:
>> 1) The flow wishes to invalidate all current pages, so calls Session.clear()
>> 2) Then the user is redirected to a new page with setResponsePage(new
>> NextPage())
>> 3) Then the request ends and if cleaning up is performed at this stage, it
>> doesn't know to keep the NextPage and its links but clean everything else
>>
>> No 3 could be addressed in wicket 1.4 using the internal untouch method to
>> tell wicket NOT to store that page anymore.
> One question: what should happen when the user is redirected to
> NextPage (because of setResponsePage(new NextPage())) and
> the user clicks on a Link ?
> Wicket will try to find the page to execute Link#onClick() but since
> the page is not stored Wicket will throw PageExpiredException.
> The same will happen if the user refreshes the page with F5.
> How do you handle that case ?
>
> Session.clear() removes all pages stored so far. If you use
> setResponsePage(anInstance) then a new page will be stored afterwards.
> If you really want to clear all pages even the NextPage instance then
> you can do:
>
> class MyRequestCycle extends RequestCycle {
>    private boolean fullClean;
>
>    public void fullClean() {
>      fullClean = true;
>    }
>
>    @Override
>    public void detach() {
>      super.detach();
>
>      if (fullClean) {
>         fullClean = false;
>         Session.get().clean();
>      }
>    }
> }
>
>> What appears to work is create a public method in my session which calls:
>>     getSessionStore().invalidate(RequestCycle.get().getRequest());
>>
>> This seems to work (and is part of what replaceSession() does) but I don't
>> know the internals of the new PageManager et al so I'm not sure if this is
>> already enough and correct?
>>
>> Matt
>>
>> On 2011-11-02 13:27, Martin Grigorov wrote:
>>> On Wed, Nov 2, 2011 at 2:09 PM, Matthias Keller
>>> <matthias.keller@ergon.ch>    wrote:
>>>> Hi Martin
>>>>
>>>> Thanks for the quick reply.
>>>> The fix doesn't work for me though, I can still go back and press reload

>>>> or
>>>> do anything I like.
>>>> If I use session.replaceSession() it works as expected but as a side
>>>> effect
>>>> also changes the JSESSIONID which usually isn't what you want...
>>>>
>>>> I'm using it like that in an onClick event of a button (and the session
>>>> is
>>>> NOT temporary):
>>>>
>>>>         if (getSession().isTemporary() == false) {
>>>>             getSession().getPageManager().sessionExpired(getId());
>>>>         }
>>> This code does the same as in 1.4 with page maps.
>>> #untouchPage() as internal API in 1.4 and is not ported to 1.5.
>>>
>>> Try by override Session#detach() and do:
>>> super.detach();
>>> clear();
>>>
>>>>         setResponsePage(new ConfirmationPage(...));
>>>>
>>>> Maybe it could be some kind of special situation like it was in Wicket
>>>> 1.4
>>>> where I manually had to untouch the current page to avoid it still being
>>>> stored at the end of the request...?
>>>>
>>>> Matt
>>>>
>>>>
>>>> On 2011-11-02 10:40, Martin Grigorov wrote:
>>>>> I implemented the feature in the ticket Matt created.
>>>>> Please try it.
>>>>>
>>>>> On Wed, Nov 2, 2011 at 11:35 AM, Andrea Del Bene<adelbene@ciseonweb.it>
>>>>>   wrote:
>>>>>> Have you tried session.invalidate()? If you have an
>>>>>> AuthenticatedWebSession
>>>>>> you can also use signOut()
>>>>>>> Hi
>>>>>>>
>>>>>>> Upon logging out we need to keep the current user's session to
still
>>>>>>> display some information but we want to remove all previous pages
from
>>>>>>> the
>>>>>>> PageMap (or however that is solved in Wicket 1.5 now) so that
he
>>>>>>> cannot
>>>>>>> go
>>>>>>> back and continue on these pages.
>>>>>>> In Wicket 1.4 we found a way to achieve that, basically with
>>>>>>>   session.clear()  (plus  session.untouch(getPage())  ). In Wicket
>>>>>>> 1.5.2
>>>>>>> the
>>>>>>> clear() method ist still there, but only contains an empty TODO
>>>>>>> comment....
>>>>>>>
>>>>>>> How do we clear the previous pages now so that if he goes back,
the
>>>>>>> user
>>>>>>> receives a PageExpiredError ?
>>>>>>>
>>>>>>> Thanks a lot
>>>>>>>
>>>>>>> Matt
>>
>>
>>
>
>


-- 
matthias.keller@ergon.ch  +41 44 268 83 98
Ergon Informatik AG, Kleinstrasse 15, CH-8008 Z├╝rich
http://www.ergon.ch
______________________________________________________________
e r g o n    smart people - smart software



Mime
View raw message