Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page applies to Wicket 1.3/2.0

Normally, you'd use one of the following to redirect to a Wicket page:

...

If you're trying to integrate with JSPs or similar, you may need to redirect to a non-Wicket page. There's a Response.redirect() method for doing this, but you need to jump through a couple of hoops to make it work, like so:Do use then the RedirectRequestTarget where you can specify an url.

Code Block
public void onSubmit()
{
    // [...]

    // Tell Wicket we're going to do the redirect ourselves.
    getRequestCycle().setRedirect(false);

    // Make sure no output for the current cycle is ever sent.
    getRequestCycle().setRequestTarget(EmptyRequestTarget.getInstance());

    // The HTTP RFC says redirects should always be absolute, so we
    // make an absolute path by prefixing with the context path.
    String contextPath = getApplication().getApplicationSettings().getContextPath();
    getResponse
    // Make sure no output for the current cycle is ever sent.
    getRequestCycle().redirectsetRequestTarget(new RedirectRequestTarget(contextPath + "/path/to/legacyJspFile.jsp"));

}

Note that if you just want to make standard anchor tag links to other pages, don't create a Link and use this method in the onClick() handler; instead use the ExternalLink class.