Re: Returning a list with name/value pair parameters
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Friday, February 4, 2011, 6:00:35 PM, Chris wrote:
> Is it possible to return a List / TemplateSequenceModel from code that
> accepts parameters formatted as name / value pairs?
>
> Here's what I want to do:
>
> <#assign myList = myMethod(param0="value" param1="value")>
>
> or
>
> <#assign myList = <@myMethod param0="value" param1="value"/> >
>
> The trouble with the first example is that the TemplateMethodModel above
> only accepts positional parameters, not name/value pairs.
Unfortunately that's like that. The 3.0 branch can do this using
annotations on the Java-side, but the 3.0 efforts seems to be dead. It
still could be added to 2.4 (as that require J2SE 1.5 anyway)...
however that wasn't done yet.
> The trouble with the second example is that I don't think this syntax works.
That (markup to plain value) is illegal, and most certainly will
remain so due to the problems it causes with #escape.
> The reason I want name/value pairs is that the parameters are definitely
> going to change over time, and it's a lot easier to be backwardly
> compatible when you use them. You can add new ones and ignore old ones
> without a problem. With positional parameters, you're stuck.
Yeah, I used to miss them in Java too... Right now you could use a
hash as parameter:
myMethod({"param0": "value" "param1": "value"})
but it's very ugly. Or, you could sign a CLA and backport this feature
from 3.0. (; Contributions are highly welcome.
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
The modern datacenter depends on network connectivity to access resources
and provide services. The best practices for maximizing a physical server's
connectivity to a physical network are well understood - see how these
rules translate into the virtual world?
http://p.sf.net/sfu/oracle-sfdevnlfb