For exaclty the same problem, this is what I use. Feel free to take it.

import java.net.MalformedURLException;
import java.net.URL;

import javax.servlet.http.HttpServletRequest;

import wicket.Page;
import wicket.protocol.http.WebRequest;
import wicket.protocol.http.WebRequestCycle;
import wicket.request.IRequestCodingStrategy;
import wicket.request.target.component.BookmarkablePageRequestTarget;
import wicket.request.target.component.IBookmarkablePageRequestTarget;

public class ClickbackPage
{
    public static <T extends Page>String getClickbackPageUrl(
            final WebRequestCycle webRequestCycle,
            final Class<T> pageClass )
        throws MalformedURLException
    {
        final WebRequest webRequest = webRequestCycle.getWebRequest();
        final HttpServletRequest request =
webRequest.getHttpServletRequest();
        final String urlString = request.getRequestURL().toString();
        final URL url = new URL( urlString );
        final int port = url.getPort();
        final int defaultPort = url.getDefaultPort();

        final IBookmarkablePageRequestTarget target =
            new BookmarkablePageRequestTarget( pageClass );
        final IRequestCodingStrategy parentStrategy =
            webRequestCycle.getProcessor().getRequestCodingStrategy();

        final String pagePath = parentStrategy.encode( webRequestCycle,
target ).toString();

        final StringBuilder s = new StringBuilder();
        s.append( url.getProtocol() ).append( "://" );
        s.append( url.getHost() );
        if( port != defaultPort && port != -1 )
            s.append( ":" ).append( port );
        s.append( pagePath );

        final URL clickbackPageUrl = new URL( s.toString() );
        return clickbackPageUrl.toString();
    }
}


> -----Original Message-----
> From: Justin Morgan (Logic Sector) [mailto:[EMAIL PROTECTED]
> Sent: 16 August 2007 17:23
> To: [email protected]
> Subject: Given a Page subclass and its PageParameters, how to
> determine the URL string?
>
>
> Hi,
>
> (I've poked around the Wicket mailing list archives and FAQ and
> haven't seen an obvious solution for this.)
>
> My question:
> How do I to determine in advance what the encrypted URL string of a
> page (plus its parameters) will be?  In case it matters, I'm using
> CryptedUrlWebRequestCodingStrategy.
>
> The reason for the question:
> I've created a rudimentary "VerifyEmailPage" in my app that takes an
> email address as a page parameter.  A URL string will be put in an
> email message and sent to a user when that user creates an account.
> (The URL string accesses the VerifyEmailPage.)  The user then clicks
> on the URL in the email in order to validate the email address.  I
> need a way to determine what that URL should be (so I can send the
> URL to them).
>
> Thanks for any info,
>
> Justin
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to