Erika Madja
Erika Madja

Reputation: 111

Wicket: How to remove or skip a page in the pagemap?

Is there a way in wicket 1.4 to “skip” a page in the pagemap when the user navigates with the Back and Forward buttons?

Simply removing the page from the pagemap generates an exception: org.apache.wicket.protocol.http.PageExpiredException: Cannot find the rendered page in session [pagemap=null,componentPath=3,versionNumber=0]

Here is my use case: I have a report creation page. The user clicks a button to confirm the report and is redirected to a report pending page which displays the progress of the report process until the actual report is regenerated. The user is then redirected to the report page.

report creation page --> report pending page --> report result page.

Once the report is generated, I do not want the user to be able to navigate back (and forward) to the report pending page. I tried navigating to the “report creation page” when the user navigates to the report pending page. Below in the onBeforeRender() of the report pending page.

@Override
public void onBeforeRender() {

    if (!reportPending && previousPage != null) 
    {
        RequestCycle.get().setRedirect(true);
        RequestCycle.get().setResponsePage(previousPage);
    } 

    super.onBeforeRender();
}

In I.E., it works ok, but then I end up with the “report creation page” showing twice when the user goes back twice. report result page -(back)-> report creation page -(back) ->) report creation page. Not ideal.

In Firefox, each time I hit the back button, I get the “report creation page” infinitively. Basically it is as if the back button indefinitely points to the report pending page.

Is there a way I can remove the report pending from the browsing history (pagemap) without getting an exception? Any insight is appreciated. Thank you in advance.

Upvotes: 2

Views: 1729

Answers (2)

user250343
user250343

Reputation: 1183

A very simple, non-Wicket specific suitable concept is to return the content of the result with exactly the same URL as the URL before it i.e. of the first page that you don't want to show with the back button. This can be done with or without response redirect. In both cases no browser history entry is created and one does not have to guess which page to show on back button.

In Wicket use a mounted page with setVersioned(false). The page contains initially a creation panel. As a result of the report creation, the creation panel gets replaced with a report panel. The panel replacement method avoids creation of two pages.

There is a complication though. You need a mapper that does not create a version string at all, that basically supports the setVersioned() directive. Support/Implementation of this does not exist out of the box in versions 1.4 ... 6.5. Without it, there are always two pages, one initial without the version in its URL, and one with something like ?0 as version string.

Upvotes: 1

Martijn Dashorst
Martijn Dashorst

Reputation: 3692

What you could try—I haven't done this myself—is to throw a RestartResponseException in your onBeforeRender override. The problem then becomes which page to show: is the user going back to the create report page, or forward to the download page? You can look at the last rendered page in the page map, but this is bound to annoy users when you don't make it work perfectly.

Instead of this page magic you could create a (modal) progress bar that is shown at the create page, skipping the intermediate page, and upon completion either show a download link, or redirect the browser to the download page.

Upvotes: 1

Related Questions