tags:

views:

38

answers:

2

Hello all,

I need to retrieve URL from current Web page opened in Firefox by using Wicket. Can somebody tell me how to do that?

Thanks!

+1  A: 

Depending on what exactly you want, this may not be possible. There is a short guide here in the Wicket wiki, but it has some caveats, notably that it only returns a relative URL in versions of Wicket after 1.3. That said, the method used is

String url = urlFor("pageMapName", MyPage.class, new PageParameters("foo=bar"));

If you go with the wiki's alternate method — the one involving the form — be warned: getPage() is not part of Wicket's public API.

Lord Torgamus
A: 

You need to query the underlying HTTPServletRequest:

public class DummyPage extends WebPage{

    private String getRequestUrl(){
        // this is a wicket-specific request interface
        final Request request = getRequest();
        if(request instanceof WebRequest){
            final WebRequest wr = (WebRequest) request;
            // but this is the real thing
            final HttpServletRequest hsr = wr.getHttpServletRequest();
            String reqUrl = hsr.getRequestURL().toString();
            final String queryString = hsr.getQueryString();
            if(queryString != null){
                reqUrl += "?" + queryString;
            }
            return reqUrl;
        }
        return null;

    }

}

Reference:

seanizer