Summarization of different ways to redirect or render another response in Apache Wicket.


Some of the sources:


Redirection in wicket basically revolves around IRequestHandler implementations.

Martin Grigorov wrote:

IRequestHandler (IRH) is the improved IRequestTarget from 1.4. Read

RequestCycle's javadoc for more information about the scheduling of


Basically the idea is that the request processing starts with a IRH

that is resolved by the request url, then later during processing a

new IRH can be scheduled to be executed after the current one (e.g.

using setResponsePage() will do that). At the end only the last

scheduled IRH actually writes to the http response.


There are 2 kinds of redirects:


A) In event handlers - links etc.



add( new Link("link"){
     @Override void onClick(){
         setResponsePage( new MyPage( new PageParameters().add("product", product).add("release", release) );



add( new DownloadLink("download"){

     ... (TBD)



redirectToInterceptPage & continueToOriginalDestination()

First, redirectToInterceptPage() "stores" the current page and redirects to e.g. a sing-in page.

Then, continueToOriginalDestination() redirects back to this stored page, e.g. when user is done with signing-in.


B) During page initialization.



Renders another page.

Useful if navigated to a page with invalid params (nonexistent id etc.)



If actual HTTP redirection is needed.







import org.apache.wicket.request.flow.RedirectToUrlException;
throw new RedirectToUrlException(
    ""+ _apiKey + "&v=1.0");


Using HTTP 301 ("Moved Permanently", SEO friendly):

import org.apache.wicket.request.flow.RedirectToUrlException;
import javax.servlet.http.HttpServletResponse;
throw new RedirectToUrlException(
""+ _apiKey + "&v=1.0",