velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ravikanth.L" <ravikanth_lo...@yahoo.com>
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
element.

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
null.

For example :

I have the hierarchy

--- 001 (id)
    --002
       -- 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,
Ravikanth.L



		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
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