what i would do is make the real server/port configurable in your application object
So that you can just do
String fullUrl = YourApplication.get().getServerUrl() + urlFor(xxx);

That is much better because you have no idea that  req.getServerName(); will work for you
Tomcat could be virtual hosted or what ever..

johan


On 7/15/06, Philip A. Chapman < [EMAIL PROTECTED]> wrote:
I have a need to create a url to be put into an email.  The code is in a service class without direct access to a Page or Component.  At first glance, I thought that WebRequestCycle.urlFor would do the trick.   I soon found out that it only gives me the relative path.  After some work, I came up with the following code:

import javax.servlet.http.HttpServletRequest;
import wicket.Page;
import wicket.PageParameters;
import wicket.RequestCycle;
import wicket.protocol.http.WebRequest;
import wicket.protocol.http.WebRequestCycle;


/**
* Builds a fully qualified path to the indicated page with the given
* parameters.
* @param pageClass The class of the Wicket page to link to.
* @param pageParameters The parameters to send to the page.  Send an empty
*                       PageParameters instance if there are no parameters to send.
* @return The url in the form of a String.
*/
public String buildFullyQualifiedPath(
Class<? extends Page>pageClass, PageParameters pageParameters
)
{
StringBuilder sb = new StringBuilder();
WebRequestCycle cycle = (WebRequestCycle)RequestCycle.get();
HttpServletRequest req = ((WebRequest)cycle.getRequest()).getHttpServletRequest();
sb.append("http://").append(req.getServerName());
if (req.getServerPort() != 80) {
sb.append(':').append(req.getServerPort());
}
sb.append(cycle.urlFor(null, pageClass, pageParameters));
return sb.toString();
}

This works well enough, but seems a bit hackish.  I was wondering if anyone else had come up with a better solution.

Thanks,

-- 
Philip A. Chapman

Desktop and Web Application Development:
Java, .NET, PostgreSQL, MySQL, MSSQL
Linux, Windows 2000, Windows XP



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQBEuVY+AdpynRSGw3URAjzcAJ0XZwQUtbm2cKpXdOqMNBIZmTI25wCfZrOF
boGcZGmASaI337gzbhqjeZ0=
=ki1E
-----END PGP SIGNATURE-----



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642


_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to