Redirect to external non-Wicket page in Wicket 1.5

Laban Okune Anunda picture Laban Okune Anunda · Apr 27, 2011 · Viewed 7.3k times · Source

How do I do the following in Wicket 1.5?

page.getRequestCycle().setRequestTarget(new RedirectRequestTarget("http://www.facebook.com/login.php?api_key="+ _apiKey + "&v=1.0"));

I want to do a Facebook application using Wicket 1.5, and I want at some point to redirect the user to the Facebook login page. A lot has changed as highlighted in Migrating to Wicket 1.5.

Answer

sother picture sother · Jun 28, 2011

Using HTTP 302 ("Moved Temporarily"):

import org.apache.wicket.request.flow.RedirectToUrlException;
...
throw new RedirectToUrlException(
    "http://www.facebook.com/login.php?api_key="+ _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(
    "http://www.facebook.com/login.php?api_key="+ _apiKey + "&v=1.0", 
    HttpServletResponse.SC_MOVED_PERMANENTLY);