Re: Given a Page subclass and its PageParameters, how to determine the URL string?

2007-08-16 Thread Justin Morgan (Logic Sector)
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 pageParameters.
 *
 * @param webRequestCycle
 *a Wicket WebRequestCycle instance
 * @param pageParameters
 *parameters for the page
 * @return a URL in string form for the page plus parameters, or  
null

 * 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 String getClickbackPageUrl(
final WebRequestCycle webRequestCycle,
final Class 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: users@wicket.apache.org
Subject: Given a Page subclass and its PageParameters, how to
determine the URL string?


Hi,

(I've poked around 

Re: Given a Page subclass and its PageParameters, how to determine the URL string?

2007-08-16 Thread Igor Vaynberg
urlfor(mymountedpageclass, mypageparameters)

-igor


On 8/16/07, Justin Morgan (Logic Sector) <[EMAIL PROTECTED]> wrote:
>
> 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]
>
>


RE: Given a Page subclass and its PageParameters, how to determine the URL string?

2007-08-16 Thread David Leangen

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 String getClickbackPageUrl(
final WebRequestCycle webRequestCycle,
final Class 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: users@wicket.apache.org
> 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]



Re: Given a Page subclass and its PageParameters, how to determine the URL string?

2007-08-16 Thread Oliver Lieven

Hi,

I'm doing this by mounting an alias-name to the page in the application's
init()-method by calling 

WebApplication.mountBookmarkablePage(
  java.lang.String path,java.lang.Class bookmarkablePageClass) 

e.g. mountBookmarkablePage("verifyEmail", VerifyEmailPage.class)

Then you can send an email with a link like
www.yourapp.com/verifyEmail?...params ...

Regards,
Oliver


Justin Morgan (Logic Sector) wrote:
> 
> 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]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Given-a-Page-subclass-and-its-PageParameters%2C-how-to-determine-the-URL-string--tf4278204.html#a12177813
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Given a Page subclass and its PageParameters, how to determine the URL string?

2007-08-16 Thread Justin Morgan (Logic Sector)

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]