velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: LinkTool.addRequestParams is difficult to use due to varargs/String[] parameter [fixed]
Date Wed, 27 Jul 2011 22:27:32 GMT
Fixed in 2.0.x branch.

On 7/27/2011 4:49 PM, Christopher Schultz wrote:
> Nathan,
> On 7/27/2011 4:40 PM, Nathan Bubna wrote:
>> On Wed, Jul 27, 2011 at 11:59 AM, Christopher Schultz
>> <> wrote:
>>> All,
>>> I've been trying to switch my templates from using
>>> LinkTool.addIgnore()....addAllParameters() to use
>>> LinkTool.addRequestParamsExcept(String... allButThese) but I'm having a
>>> bit of difficulty with it.
>>> If I call addRequestParams() with no argument, things work as expect. On
>>> the other hand, this does not work:
>>> #set($ignoreList = ['foo'])
>>> $link.relative('/bar').addRequestParamsExcept($ignoreList)
>>> I get an invalid reference log message and the above "$link..." text is
>>> rendered as written instead of evaluating successfully.
>>> Without much investigation, I believe the problem is that the ignoreList
>>> is a List and it needs to be String[]. Velocity will auto-convert Lists
>>> into Object[] if appropriate, but I suspect that the resulting object
>>> type is Object[] and not, say, String[].
>> i believe you're right.
>>> There does not appear to be a way to create a String[] from a Velocity
>>> template, so using addRequestParams and the other, similar methods will
>>> be very difficult to use with an argument.
>> why not just do $link.addRequestParamsExcept('foo', 'bar', 'etc')?
> When you've got an array (or list) of items, it's tough to turn it into
> a varargs call :) I don't know the list of "ignore" items beforehand, so
> I can't hard-code the list into the template. Instead, a calling
> template needs to set up some kind of variable that contains that ignore
> list.
>>> If anyone has any suggestions for how to use these methods with
>>> template-supplied data, I'd love to hear them. Otherwise, I'm inclined
>>> to either overload or modify these methods to accept an Object[]
>>> parameter and throw an exception if the array elements are not String
>>> objects.
>> i think that would be a good enhancement regardless.  i don't
>> particularly like templates and tools being picky about types when
>> they don't have to be.
> Okay, I'll go ahead and log it.
> -chris

View raw message