velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sriram Gopalan" <sgopa...@salesforce.com>
Subject RE: Nested, cartesian loop of dynamic values
Date Fri, 12 May 2006 16:11:50 GMT
Thanks, guys. I made this work before the reply emails came, by using
reflection, a two dimensional array and a callback object. I didn't have
to use rendertool

Thanks again for all the help.

- Sriram Gopalan 

-----Original Message-----
From: apache@recks.org [mailto:apache@recks.org] 
Sent: Friday, May 12, 2006 12:46 AM
To: Velocity Users List
Subject: Re: Nested, cartesian loop of dynamic values

Claude pointed already in the right direction.
Your inquiry is clear enough to give a concrete
(untested) code snippet using the RenderTool:

#foreach ($function in $functions)
   #foreach ($parameter in $parameters)
     $render.eval($ctx, "${object}.${function}(${parameter})")
   #end
#end

Your example was missing the object onto which the function is to be
applied.

The example above has the context object name in the $object context
variable.

If the $object reference name is known at template writing time, you can
use the the reference name directly, but it must be escaped until the
eval call:
     $render.eval($ctx, "\$object.${function}(${parameter})")

Cheers,
Christoph

Sriram Gopalan wrote:
> Hi, Here is my requirement. I have a list of function objects in java 
> that I can put into my velocity context. All these functions (methods)

> take one parameter each. I also have this list of parameters that the 
> functions take. I need to be able to print the invoked return value of

> these methods into my output file.
>  
> As an example, assume my functions are:
>  
> functions = {'getName', 'getAge','getSalary'...}; parameters = 
> {'John','Joe','Jack','Mary'...}
>  
> and I want the output to be of the following format:
>  
> getName('John') = John Smith
> getName('Joe') = Joe Doe
> .
> .
> .
> getAge('Jack') = 36
> .
> .
> .
> getSalary('Mary') = 30000
> .
> .
> .
>  
> and so on. I hope my predicament is clear. The left hand side of the 
> output lines are easy ($function.name, $parameter.name etc.) However, 
> the right hand side is dynamic and actually depends on the runtime 
> evaluated output value of invoking $function on $parameter. What are 
> the various ways in which I can do this? What would my template look
like?
>  
> #foreach ($function in $functions)
>     #foreach ($parameter in $parameters)
>  
> $function.name('$parameter.name') = ## ???? WHAT COMES HERE?
>  
>     #end
> #end
>  
> Thanks for the help in advance.
>  
> regards,
> Sriram Gopalan
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message