Search code examples
wicket-6

Wicket 6.22 Automatic redirection to external URL


I have a wicket (6.22) web application. I need to perform automatic redirection to an external URL. The scenario is described bellow:

  1. The customers enter their data in a form
  2. The server processes several actions and displays a result page
  3. The result page should last 5 seconds and then automatically redirect customers to an external URL. The result page contains a "back" link, so the customers may click on it to be redirected to the same external URL.

I did use "renderHead" function to add tag

<meta http-equiv="refresh" content="5; url=http://example.com">

The issue is that I need to invalidate the session before the redirection. If I do so, the customers are redirected to my ExpiredSession page instead of the external URL.

Is their any clean solution to make it happend?

Thank you for your help


Solution

  • Instead of using <meta http-equiv="refresh" content="5; url=http://example.com"> you can set up an Ajax behavior that will: 1) invalidate the session; 2) redirect to the external page

     anyComponent.add(new AbstractAjaxTimerBehavior(Duration.seconds(5)) {
         @Override protected void onTimer(AjaxRequestTarget target) {
           getSession().invalidate();
           throw new RedirectToUrlException("https://external.page");
        }
     });