Note that there are some explanatory texts on larger screens.

plurals
  1. POForce page expiration in wicket 1.5.8
    primarykey
    data
    text
    <p>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 <code>getPage().getPageMap().clear()</code>. Now in wicket 1.5, page map is gone, and I can't figure out how to dot that.</p> <p>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 <code>getPageSettings().setRecreateMountedPagesAfterExpiry(true);</code> 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).</p> <p>Looking around I found the possibility to use <code>Session.get().clear();</code> 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.</p> <p>Supposing the wizard is mounted at <code>/wizard</code>, redirecting to <code>/list</code> at the end, the flow would be something like: <code>/wizard?1</code>, <code>/wizard?2</code>, <code>/wizard?3</code>, <code>/list</code>. Now when I use the back button, <code>/wizard?3</code> is not expired, although <code>/wizard?1</code> and <code>/wizard?2</code> are as expected. The session clearing and sending to the list page are done in the <code>onFinish</code> method of the wizard, which reads like this:</p> <pre><code>@Override public void onFinish() { Session.get().clear(); Session.get().getFeedbackMessages().add(new FeedbackMessage(..)); setResponsePage(ListPage.class); } </code></pre> <p>So, come to the question itself: would anyone know how to get the expected behaviour, i.e. expiring <code>/wizard?3</code> as well?</p> <p>Thanks</p> <p>Note: <code>ListPage</code> is a bookmarkable page and I tried as well with <code>setResponsePage(new ListPage());</code></p> <hr> <p><strong>Update with what I finally did base on Andrea's suggestion</strong></p> <p>It is to be noted that my application uses a custom session object extending wicket's <code>Session</code>; let's call it <code>AppSession</code>.</p> <ol> <li>in <code>AppSession</code>, I added a <code>boolean clearRequested</code> attribute (defaults to false)</li> <li>in <code>AppSession</code>, I added a static void method <code>requestClear()</code> which is just a shortcut to set <em>clearRequested</em> to true in the session</li> <li>in the <code>onFinish()</code> of my wizard, just before calling <code>setResponsePage</code>, I call <code>AppSession.requestClear()</code></li> <li><p>lastly I just add a <code>RequestCycleListener</code> to my application.</p> <pre><code>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); } } }); </code></pre></li> </ol> <p>Now anytime I need to clear session after an action in order to expire pages, I juste call <code>AppSession.requestClear()</code> and in the next request the session is cleared.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload