Pergunta

I'm trying to expire all previous versions of a given page with Wicket 1.5.8. In wicket 1.4, it was done by getPage().getPageMap().clear(). Now in wicket 1.5, page map is gone, and I can't figure out how to dot that.

My use case is that I have a wizard (http://www.wicket-library.com/wicket-examples/wizard/) to create/edit an entity. When the wizard is submitted, the user is redirected to the entities list. At this point I don't want the user to be able to use the browser back button to go back to the wizard in the state it was, and thus want to expire previous versions of the page with the wizard (I am using getPageSettings().setRecreateMountedPagesAfterExpiry(true); so the mounted page will be recreated in a blank state if the page expires when the user goes back, which is what I want).

Looking around I found the possibility to use Session.get().clear(); which removes all pages from the Session (I don't know if the 1.4 version was removing all pages or just all versions of the page used to access the PageMap - which would be better for multi-tab support). However, using that works only partly, as the last page is not expired.

Supposing the wizard is mounted at /wizard, redirecting to /list at the end, the flow would be something like: /wizard?1, /wizard?2, /wizard?3, /list. Now when I use the back button, /wizard?3 is not expired, although /wizard?1 and /wizard?2 are as expected. The session clearing and sending to the list page are done in the onFinish method of the wizard, which reads like this:

@Override
public void onFinish() {
  Session.get().clear();
  Session.get().getFeedbackMessages().add(new FeedbackMessage(..));
  setResponsePage(ListPage.class);
}

So, come to the question itself: would anyone know how to get the expected behaviour, i.e. expiring /wizard?3 as well?

Thanks

Note: ListPage is a bookmarkable page and I tried as well with setResponsePage(new ListPage());


Update with what I finally did base on Andrea's suggestion

It is to be noted that my application uses a custom session object extending wicket's Session; let's call it AppSession.

  1. in AppSession, I added a boolean clearRequested attribute (defaults to false)
  2. in AppSession, I added a static void method requestClear() which is just a shortcut to set clearRequested to true in the session
  3. in the onFinish() of my wizard, just before calling setResponsePage, I call AppSession.requestClear()
  4. lastly I just add a RequestCycleListener to my application.

    getRequestCycleListeners.add(new AbstractRequestCycleListener() {
      @Override
      public void onBeginRequest(RequestCycle cycle) {
        super.onBeginRequest(cycle);
        AppSession session = AppSesssion.get();
        if (session.isClearRequested()) {
          session.clear();
          session.setClearRequested(false);
        }
      }
    });
    

Now anytime I need to clear session after an action in order to expire pages, I juste call AppSession.requestClear() and in the next request the session is cleared.

Foi útil?

Solução

you could clear your session in ListPage. Since this page is bookmarkable you could pass it a page parameter indicating that ListPage must get rid of the pages in session.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top