Today I was working with a "Facebook interface" to an application being rewritten with Wicket. I needed to do a redirect, and as you probably know, a "normal" redirect does not work if the Facebook app is running in the "FBML mode".

Facebook provides a custom tag to accomplish a redirect within the Facebook canvas - Fb:redirect (

I ended up doing a custom IRequestTarget implementation for this purpose, and thought I'd share what I came up with here. Please bear with my very limited experience with Wicket, I was just happy to get it working for my simple need. Feel free to edit/add to this as you see fit.

This is how I use it in my code, relevant code below:

page.getRequestCycle().setRequestTarget(new FBRedirectRequestTarget(SomeCanvasPageToRedirectTo.class));

Custom request target:

import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.request.IRequestCycleProcessor;

public class FBRedirectRequestTarget extends BookmarkablePageRequestTarget
    public FBRedirectRequestTarget(Class pageClass)
        this(pageClass, null);

    public FBRedirectRequestTarget(Class pageClass,
            PageParameters pageParameters)
        super(null, pageClass, pageParameters);

    public void respond(RequestCycle requestCycle)
        IRequestCycleProcessor processor = requestCycle.getProcessor();
        String redirectUrl = processor.getRequestCodingStrategy().encode(
                requestCycle, this).toString();
        Page page = new FBRedirectPage(redirectUrl);


Simple page for the FBML markup:

package com.unet.sniff.view.pages.facebook;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;

public class FBRedirectPage extends WebPage
    public FBRedirectPage(String url)
        add(new Label("redirect").add(new SimpleAttributeModifier("url", url)));

Markup for the above page (FBRedirectPage.html):

<fb:redirect wicket:id="redirect" url="#" />
  • No labels