WARNING: This server is unstable and will be retired in the next days. If you want to keep this forum available, please request immediately a migration on the Nabble Support forum. Forums that don't receive any migration request will be deleted forever.

 « Return to Thread: LinkTool.addRequestParams is difficult to use due to varargs/String[] parameter

LinkTool.addRequestParams is difficult to use due to varargs/String[] parameter

by Christopher Schultz-2 :: Rate this Message:

| View in Thread

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

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
objects.

Thanks,
-chris



signature.asc (268 bytes) Download Attachment

 « Return to Thread: LinkTool.addRequestParams is difficult to use due to varargs/String[] parameter