velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <nbu...@gmail.com>
Subject Re: [tools] StrutsLinkTool's setForward method has different behavior
Date Tue, 26 Jul 2011 22:08:28 GMT
On Tue, Jul 26, 2011 at 2:27 PM, Christopher Schultz
<chris@christopherschultz.net> wrote:
> All,
>
> We use StrutsLinkTool pretty much everywhere and had been relying on the
> previous behavior (tools 1.4) of StrutsLinkTool.setForward(String) which
> takes a reference to a Struts-defined "forward" which is basically just
> a URL.
>
> In the past, we were able to define a URL in Struts like this:
>
> <forward name="some-reference" path="/path/to/resource?foo=bar" />
>
> Then, in the markup:
>
> <a href="$link.setForward('some-reference')">link text</a>
>
> It appears that somewhere in the modifications, the URL ha sbeen
> sanitized and now "/path/to/resource?foo=bar" has been helpfully
> replaced by "/path/to/resource%3Ffoo=bar".
>
> Was this intentional? Is there a way to get the old behavior back?

It was unintentionally changed, in part because i wasn't aware that
forwards could/would contain query strings.  Basically, setForward
passes the url to absolute(url) which would correctly handle absolute
urls with query strings but treats relative urls as merely paths,
without parsing out anchors or query strings.

I think we should adapt both $link.relative($url) and
$link.absolute($url) to accept paths with query strings and anchors.
This probably will require a setFromURI(url, withoutOverriding)
adapted from what absolute($url) does for actual absolute URIs.

In the meantime, try this:

context.put(java.net.URLDecoder.class, "url");

$url.decode($link.setForward('some-reference'))

Or extend StrutsLinkTool to do that for you.

> Thanks,
> -chris
>
>

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


Mime
View raw message