velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Miller" <>
Subject Re: Variable method name in a macro?
Date Wed, 25 Sep 2002 22:48:24 GMT
First off, I had a look around the CVS contrib dirs and the Tools
subproject, but still couldn't see your tool code.

I've been trying to implement this myself. However I'm still missing either
a vital piece of information, or, more likely, a vital piece of my brain.

I am trying to achieve something like the following:

#set($method = 'propertyName')
#foreach($option in $list)

So far I have the following code in my tool:

   public String eval(String str) throws Exception
       StringWriter writer = new StringWriter(100);
       Velocity.evaluate(context, writer, "postEval", str);
       return writer.toString();

Note that I pass the context into the tool's constructor, and then put the
tool into the context before merging my original template :-)

This however still does not work - the eval() method does not get called.
I've also tried using $tool.eval("\option.get$method()"), which doesn't even
parse properly. Any tips on what I'm still missing?


> 2) Velocity doesn't do evaluation interpolation for introspection (that
> phrase may not make sense?)
>    $formBean.$method
> does *not* work.
> However, you can easily make a tool (I have said this same thing 3-4 times
> this week - I am going to just write it and put in contrib at this point
> prove my learning curve isn't flat) where you *can* do
>   $tool.eval("\$formBean.get$which()")
> such that the eval(String) method gets, with $which -> "FirstName",
>    $formBean.getFirstName()
> and then your tool can just evaluate that against the context.
> Does that make sense?
> --
> Geir Magnusson Jr.
> Research & Development, Adeptra Inc.
> +1-203-247-1713

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message