velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ravikanth.L" <>
Subject Re: constructing variable names dynamically
Date Thu, 16 Sep 2004 19:02:32 GMT
Hi All,

 I am facing some problem in using renderTool recurse
when used in macro which will be recursively executed.

The scenario is:
I am having an object which contains elements and its
associated values and the list child elements which
should be recursively processed same as the parent

I was using the following:
#macro( parseItem $catItem )
#foreach( $element in $catItem.getElementList())##
 ##loop through the element list for item and add all 
the elements to context
 #set($name = $!element.getName())##
 #foreach( $value in $element.getValueList())
   #set($theValue = false)
   #set($theValue = $!value.getValue())##
   $render.recurse($ctx,'\#set($$name = $theValue)') 
   #if($$name == "id") <!-- id value : $id and   
theValue is : $theValue --> #end
 #end ##end of value list 
#end ##end of element list
#end ##end of macro

When I execute the template recursively, elements in
the top most object are printing correctly. But when i
take the child element for that object and i called
the same macro recursively from within the macro, the
variable names which are dynamically generated using
recurse statement are not having the new value (i.e
the child element value), it still holds the parent
element value though the child element value is not

For example :

I have the hierarchy

--- 001 (id)
       -- 003

$id for the top level is printing properly, but when i
try to recursively call the same macro , for child
object , $id is still printing 001 instead of 002. But
the $theValue used in the template is giving 002 but
where as $id which has been generated dynamically is
still showing 001.

Can anyone please help me in solving this issue. I
tried clearing the contents of elements in the
beginning like 
$render.recurse($ctx,'\#set($$name = "")') 
before resetting to the new value. Still no success. 

Please correct me if i am doing something wrong.

With Regards,

Do you Yahoo!?
Declare Yourself - Register online to vote today!

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

View raw message