You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Petter Måhlén <pe...@elevance.se> on 2004/03/22 16:15:22 UTC

Generating Tapestry URL:s

Hi,

I am trying to implement this feature with email notifications being sent
out when stuff happens. For that, I would like to include links to the right
page in my web site. I am having some trouble figuring out a good way to do
that. From a layering perspective, my notification component is below
Tapestry and should be independent of it. Not that I am planning to move to
another framework, but it's poor engineering to mix layers. What I am
planning is an interface called ILinkProvider, which either my Global or
Engine class would implement. Then I could create a notifier instance that
takes a link provider as an argument, and the link provider would know what
format should be used for the links. The problem is that as far as I can
tell, in order to generate a link, you need to have a valid request cycle.
(Looking at, for instance, the way that AbstractService.getLink() works.) As
far as I can figure out, I can't get from the Global or the Engine to a
request cycle.

Does anybody know a way for me to do this without having to do something
like copy/pasting code from
org.apache.tapestry.engine.EngineServiceLink.getAbsoluteURL()?

TIA,

Petter


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: Generating Tapestry URL:s

Posted by Petter Måhlén <pe...@elevance.se>.
Thanks, it is. I have a solution which I believe works OK:

- In the initialisation method for my Global, I do:

      StringBuffer urlBase = new StringBuffer();
      urlBase.append(context.getScheme());
      urlBase.append("://");
      urlBase.append(context.getServerName());
      urlBase.append(":");
      urlBase.append(context.getServerPort());
      urlBase.append(servletPath); // comes from
AbstractEngine.getServletPath()

- Then, when I need to get somebody to log in and be redirected to a page, I
tack on a "?quickLink=xxxxx" to that.
- In pageValidate() of my base page class (from which all my pages inherit),
I check for the existence of the "quickLink" parameter. If it is found, I
lookup what the 'xxxxx' means in terms of logging in a user and redirecting
to a page.

I think that the main problems with this method is what you point out; that
the scheme and servername could possibly change. So it's not really very
generic, but for the case I am working on now, it should be fine. Initially,
I wanted to generate the whole URL directly, but I might as well store the
page to redirect to in the database.

/ Petter

> -----Original Message-----
> From: M. Stellinga [mailto:tapestry@softwaredesign.nl] 
> Sent: den 23 mars 2004 09:18
> To: Tapestry users
> Subject: Re: Generating Tapestry URL:s
> 
> 
> I think the RequestCycle is needed because the ServletRequest and 
> ServletResponse classes are needed for creating the link (and 
> these are 
> reached through the RequestContext). For example, if the 
> request is done 
> over SSL, then the scheme would be different (https instead of http).
> 
> You could try to provide your own (mostly empty) 
> implementations of the 
> IRequestCycle interface and the RequestContext.
> You might also call the createRequestCycle() method of the 
> Engine class, 
> but you would still need a RequestContext to do that.
> 
> Hope that's of some use,
> Martijn
> 
> Petter Måhlén wrote:
> 
> >Hi,
> >
> >I am trying to implement this feature with email 
> notifications being sent
> >out when stuff happens. For that, I would like to include 
> links to the right
> >page in my web site. I am having some trouble figuring out a 
> good way to do
> >that. From a layering perspective, my notification component is below
> >Tapestry and should be independent of it. Not that I am 
> planning to move to
> >another framework, but it's poor engineering to mix layers. What I am
> >planning is an interface called ILinkProvider, which either 
> my Global or
> >Engine class would implement. Then I could create a notifier 
> instance that
> >takes a link provider as an argument, and the link provider 
> would know what
> >format should be used for the links. The problem is that as 
> far as I can
> >tell, in order to generate a link, you need to have a valid 
> request cycle.
> >(Looking at, for instance, the way that 
> AbstractService.getLink() works.) As
> >far as I can figure out, I can't get from the Global or the 
> Engine to a
> >request cycle.
> >
> >Does anybody know a way for me to do this without having to 
> do something
> >like copy/pasting code from
> >org.apache.tapestry.engine.EngineServiceLink.getAbsoluteURL()?
> >
> >TIA,
> >
> >Petter
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: 
> tapestry-user-help@jakarta.apache.org
> >
> >
> >
> >  
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Generating Tapestry URL:s

Posted by "M. Stellinga" <ta...@softwaredesign.nl>.
I think the RequestCycle is needed because the ServletRequest and 
ServletResponse classes are needed for creating the link (and these are 
reached through the RequestContext). For example, if the request is done 
over SSL, then the scheme would be different (https instead of http).

You could try to provide your own (mostly empty) implementations of the 
IRequestCycle interface and the RequestContext.
You might also call the createRequestCycle() method of the Engine class, 
but you would still need a RequestContext to do that.

Hope that's of some use,
Martijn

Petter Måhlén wrote:

>Hi,
>
>I am trying to implement this feature with email notifications being sent
>out when stuff happens. For that, I would like to include links to the right
>page in my web site. I am having some trouble figuring out a good way to do
>that. From a layering perspective, my notification component is below
>Tapestry and should be independent of it. Not that I am planning to move to
>another framework, but it's poor engineering to mix layers. What I am
>planning is an interface called ILinkProvider, which either my Global or
>Engine class would implement. Then I could create a notifier instance that
>takes a link provider as an argument, and the link provider would know what
>format should be used for the links. The problem is that as far as I can
>tell, in order to generate a link, you need to have a valid request cycle.
>(Looking at, for instance, the way that AbstractService.getLink() works.) As
>far as I can figure out, I can't get from the Global or the Engine to a
>request cycle.
>
>Does anybody know a way for me to do this without having to do something
>like copy/pasting code from
>org.apache.tapestry.engine.EngineServiceLink.getAbsoluteURL()?
>
>TIA,
>
>Petter
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org