velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject LinkTool.addRequestParams is difficult to use due to varargs/String[] parameter
Date Wed, 27 Jul 2011 18:59:21 GMT

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'])

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[].

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.

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


View raw message