You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jonathan O'Connor <ni...@eircom.net> on 2009/01/02 18:51:38 UTC
T5: How to inject a Link
Hi,
it must be too much Christmas cheer, but I am not sure how to jump to a
non-Tapestry URL in the same web app.
A little background: We have an old application written in Struts 1.1. I
have written my own Login page, called the old code to the user
validation and updating of the session.
This all works ala Kent Tong's eBook on Tap4. Now I want to jump to main
struts page of my app.
My onSuccess() method needs to return a Link or a URL, but according to
the docs, the URL should be used for completely external addresses (e.g.
google.com).
Can I inject a Link (LinkImpl is in the internal package, and so unusable)?
Or should I generate a relative URL?
Thanks and Happy New Year to one and all,
Jonathan O'Connor
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: How to inject a Link
Posted by Jonathan O'Connor <ni...@eircom.net>.
Folks,
for posterity, I solved the problem using the request header fields.
1. the host header field is always guaranteed (according to the HTTP
spec http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23) to
exist.
2. The referer header field is always there because I'm handling a form
submit request from my Tap5 Login page, and therefore, the referer is my
login page.
3. I inject the RequestGlobals into my page class to get access to the
HttpServletRequest object. I could have used an injected Request object
to get the header fields and context path, but my page also needed the
underlying HttpSession and ServletContext objects.
Because I'm paranoid, I wrote the following code
HttpServletRequest req =
_requestGlobals.getHTTPServletRequest();
String referer = req.getHeader( "referer" );
String host = req.getHeader( "host" );
String contextPath = req.getContextPath();
String page = "";
if (referer != null && contextPath != null &&
referer.contains( contextPath )) {
page = referer.substring( 0, referer.indexOf(
contextPath ) ) + contextPath + "/customerSearch.jsp";
} else if (referer == null) {
page = "http://" + host + contextPath +
"/customerSearch.jsp";
}
_logger.info( "Jumping to: " + page );
return new URL(page);
Hope this helps anyone in the same boat as I was,
Jonathan
On 03/01/2009 20:22, Howard Lewis Ship wrote:
> You can return a URL no problem. The trick is to generate a proper
> URL even when behind a firewall.
>
> On Fri, Jan 2, 2009 at 9:51 AM, Jonathan O'Connor<ni...@eircom.net> wrote:
>
>> Hi,
>> it must be too much Christmas cheer, but I am not sure how to jump to a
>> non-Tapestry URL in the same web app.
>>
>> A little background: We have an old application written in Struts 1.1. I
>> have written my own Login page, called the old code to the user validation
>> and updating of the session.
>> This all works ala Kent Tong's eBook on Tap4. Now I want to jump to main
>> struts page of my app.
>>
>> My onSuccess() method needs to return a Link or a URL, but according to the
>> docs, the URL should be used for completely external addresses (e.g.
>> google.com).
>>
>> Can I inject a Link (LinkImpl is in the internal package, and so unusable)?
>> Or should I generate a relative URL?
>>
>> Thanks and Happy New Year to one and all,
>> Jonathan O'Connor
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: How to inject a Link
Posted by Jonathan O'Connor <ni...@eircom.net>.
Howard,
yes, as I suspected, when I return a URL with http://localhost:8080 etc,
the jump to the struts page works. Unfortunately, the HttpServletRequest
object doesn't know the port (it thinks it's -1), and the localAddr is
the ip address as a number, not a symbolic address, and the remote
address is null :-(
I'll let you off the hook now!
Ciao,
Jonathan
On 03/01/2009 21:12, Jonathan O'Connor wrote:
> Howard,
> I tried the following:
> HttpServletRequest req = getRequest();
> String page = "http://" + req.getLocalAddr() + ":8080/" +
> req.getContextPath() + "/myStrutsPage.jsp";
> return new URL(page);
>
> But, that returned http://127.0.0.1:8080/myApp/myStrutsPage.jsp
> instead of http://localhost:8080/myApp/myStrutsPage.jsp and that
> caused my struts app to think my session had timed out. I was hoping
> that if I created a proper Link, Tapestry would generate the proper
> URL for me :-)
> I'll go hunting,
> Ciao,
> Jonathan
>
> On 03/01/2009 20:22, Howard Lewis Ship wrote:
>> You can return a URL no problem. The trick is to generate a proper
>> URL even when behind a firewall.
>>
>> On Fri, Jan 2, 2009 at 9:51 AM, Jonathan
>> O'Connor<ni...@eircom.net> wrote:
>>> Hi,
>>> it must be too much Christmas cheer, but I am not sure how to jump to a
>>> non-Tapestry URL in the same web app.
>>>
>>> A little background: We have an old application written in Struts
>>> 1.1. I
>>> have written my own Login page, called the old code to the user
>>> validation
>>> and updating of the session.
>>> This all works ala Kent Tong's eBook on Tap4. Now I want to jump to
>>> main
>>> struts page of my app.
>>>
>>> My onSuccess() method needs to return a Link or a URL, but according
>>> to the
>>> docs, the URL should be used for completely external addresses (e.g.
>>> google.com).
>>>
>>> Can I inject a Link (LinkImpl is in the internal package, and so
>>> unusable)?
>>> Or should I generate a relative URL?
>>>
>>> Thanks and Happy New Year to one and all,
>>> Jonathan O'Connor
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: How to inject a Link
Posted by Jonathan O'Connor <ni...@eircom.net>.
Howard,
I tried the following:
HttpServletRequest req = getRequest();
String page = "http://" + req.getLocalAddr() + ":8080/" +
req.getContextPath() + "/myStrutsPage.jsp";
return new URL(page);
But, that returned http://127.0.0.1:8080/myApp/myStrutsPage.jsp instead
of http://localhost:8080/myApp/myStrutsPage.jsp and that caused my
struts app to think my session had timed out. I was hoping that if I
created a proper Link, Tapestry would generate the proper URL for me :-)
I'll go hunting,
Ciao,
Jonathan
On 03/01/2009 20:22, Howard Lewis Ship wrote:
> You can return a URL no problem. The trick is to generate a proper
> URL even when behind a firewall.
>
> On Fri, Jan 2, 2009 at 9:51 AM, Jonathan O'Connor<ni...@eircom.net> wrote:
>
>> Hi,
>> it must be too much Christmas cheer, but I am not sure how to jump to a
>> non-Tapestry URL in the same web app.
>>
>> A little background: We have an old application written in Struts 1.1. I
>> have written my own Login page, called the old code to the user validation
>> and updating of the session.
>> This all works ala Kent Tong's eBook on Tap4. Now I want to jump to main
>> struts page of my app.
>>
>> My onSuccess() method needs to return a Link or a URL, but according to the
>> docs, the URL should be used for completely external addresses (e.g.
>> google.com).
>>
>> Can I inject a Link (LinkImpl is in the internal package, and so unusable)?
>> Or should I generate a relative URL?
>>
>> Thanks and Happy New Year to one and all,
>> Jonathan O'Connor
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: How to inject a Link
Posted by Howard Lewis Ship <hl...@gmail.com>.
You can return a URL no problem. The trick is to generate a proper
URL even when behind a firewall.
On Fri, Jan 2, 2009 at 9:51 AM, Jonathan O'Connor <ni...@eircom.net> wrote:
> Hi,
> it must be too much Christmas cheer, but I am not sure how to jump to a
> non-Tapestry URL in the same web app.
>
> A little background: We have an old application written in Struts 1.1. I
> have written my own Login page, called the old code to the user validation
> and updating of the session.
> This all works ala Kent Tong's eBook on Tap4. Now I want to jump to main
> struts page of my app.
>
> My onSuccess() method needs to return a Link or a URL, but according to the
> docs, the URL should be used for completely external addresses (e.g.
> google.com).
>
> Can I inject a Link (LinkImpl is in the internal package, and so unusable)?
> Or should I generate a relative URL?
>
> Thanks and Happy New Year to one and all,
> Jonathan O'Connor
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Howard M. Lewis Ship
Creator Apache Tapestry and Apache HiveMind
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org