Many thanks to all who replied. I went with a version of David Leangen's code modified for my own use with Wicket 1.3 as follows. It's working great.

Thanks again,

Justin

import java.net.MalformedURLException;
import java.net.URL;
import javax.servlet.http.HttpServletRequest;
import org.apache.wicket.PageParameters;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.WebRequestCycle;
import org.apache.wicket.request.IRequestCodingStrategy;
import org.apache.wicket.request.target.component.BookmarkablePageRequestTarget ; import org.apache.wicket.request.target.component.IBookmarkablePageRequestTarge t;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class VerifyEmailPage extends MasterPage {
private static final Logger LOGGER = LoggerFactory.getLogger (VerifyEmailPage.class);

    /**
* Gets a URL in string form that can be used to access the VerifyEmailPage. The URL
     * will pass the supplied <em>pageParameters</em>.
     *
     * @param webRequestCycle
     *        a Wicket WebRequestCycle instance
     * @param pageParameters
     *        parameters for the page
* @return a URL in string form for the page plus parameters, or <code>null</code>
     *         if the URL cannot be obtained
     */
public static String url(final WebRequestCycle webRequestCycle, final PageParameters pageParameters) {
        try {
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(VerifyEmailPage.class,
                    pageParameters);
final IRequestCodingStrategy parentStrategy = webRequestCycle.getProcessor().getRequestCodingStrategy();

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

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

            return new URL(stringBuilder.toString()).toString();
        }
        catch (MalformedURLException e) {
            return null;
        }
    }
    ...
}


On Aug 16, 2007, at 2:28 AM, David Leangen wrote:


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]




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

Reply via email to