Get a URL of the current page in Wicket for an OAuth redirect

Get a URL of the current page in Wicket for an OAuth redirect

Problem Description:

I need to forward my user to an OAuth provider for login, and then pass a redirect URL to the OAuth provider. I’d like for the user to return to the same stateful page that they were currently on. In Apache Wicket (version 7), how can I generate a full URL that will take them back to the current page?

I’m looking for an external URL that will do the equivalent of:

add( new Link<Object>( "samePage") {
        public void onClick() {
            setResponsePage( getPage() );
    } );

Solution – 1

I use the following code to obtain a full URL of the current page, but it’s for 9.x, can’t test 7.x:

Url currentUrl = ((WebRequest)RequestCycle.get().getRequest()).getUrl();
String fullUrl = RequestCycle.get().getUrlRenderer().renderFullUrl(currentUrl);

Solution – 2

I think I figured it out – this approach generates a new render count, and works even from panels / components within the parent page:

String redirect = getRequestCycle().getUrlRenderer().renderFullUrl( Url.parse( getPage().urlFor( IRedirectListener.INTERFACE, new PageParameters() ) ) )
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.