velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claude Brisson <cla...@renegat.net>
Subject Re: Nested, cartesian loop of dynamic values
Date Fri, 12 May 2006 01:02:17 GMT
Hi

You should check the RenderTool (or the ViewRenderTool if you are using
the VelocityViewServlet).

http://jakarta.apache.org/velocity/tools/generic/RenderTool.html

To use the RenderTool tool, you've got to put it in the context, as long
as the context itself. You can then write things like

${function}('$parameter') =
$render.eval($context,"${function}.invoke($parameter)")

(I'm kinda gessing the 'invoke' syntax since I donno your function
objects...)

Considering your problem from another perspective, you could also maybe
use reflection... but you should give more details about your function
objects for hints about this option.

  Claude

Le jeudi 11 mai 2006 à 11:10 -0700, Sriram Gopalan a écrit :
> 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


Mime
View raw message