Re: Calling #Macro Recursively

rizzz86 <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>

What more I have found is that the parameter of the macro (i.e. menuList)
might be creating a problem.

Example:

I have created two macros "menugenerator1" and "menugenerator2" as follows:

>> <#macro menugenerator1 menuList>
>>         <#if menuList??>
>>                 <#foreach element in menuList>
>>                         ${element.url} ${element.title} ..... //
>> Generates
>> Menu
>>                         <#if element.children??>
>>                             <@menugenerator2 menuList=element.children/>
>>                         </#if>
>>                 </#foreach>
>>         </#if>
>> </#macro>


>> <#macro menugenerator2 menuList>
>>         <#if menuList??>
>>                 <#foreach element in menuList>
>>                         ${element.url} ${element.title} ..... //
>> Generates
>> Menu
>>                         <#if element.children??>
>>                             <@menugenerator2 menuList=element.children/>
>>                         </#if>
>>                 </#foreach>
>>         </#if>
>> </#macro>

If I call 2nd macro inside first macro (as shown) ... the 2nd macro will
actually does NOT iterate over the child of element (i.e. element.child
passed as parameter in 1st macro). But it iterates over the same element
(that is in macro 1) and that seems to be the never ending loop.

Another thing is that when I changed the "parameter names" of both the
macros (i.e. menuList and menuList1 respectvly) ... it calls the right list
in macro 2 (i.e. element.children).

Now what i am thinking is that how can I call the recursive macro with
different parameter names ?? Got something :confused:


rizzz86



Daniel Dekany wrote:
> 
> Thursday, October 15, 2009, 12:52:31 PM, Daniel Dekany wrote:
> 
>> Thursday, October 15, 2009, 6:00:35 AM, rizzz86 wrote:
>>
>>> Hi,
>>>
>>> I am trying to call <#macro> recursively.
>>> I am getting the StackOVerFlowError, which means that their are
>>> unlimited
>>> number of calls made wiithin a macro.
>>>
>>> What I was actually doing is "Rendering a Menu". I have a List that
>>> contains
>>> a menu bean. That menu bean can also have its children and these
>>> children
>>> are also a list containing a menu bean.
>>>
>>> example:
>>>
>>> class MenuBean {
>>>
>>>   String title;
>>>   String url;
>>>   List<MenuBean> children;
>>>   etc..
>>> }
>>>
>>> I can have N numbers of children for each menu (no limit).
>>>
>>> My macro is as follows:
>>>
>>> <#macro menugenerator menuList>
>>>         <#if menuList??>
>>>                 <#foreach element in menuList>
>>>                         ${element.url} ${element.title} ..... //
>>> Generates
>>> Menu
>>>                         <#if element.children??>
>>>                             <@menugenerator menuList=element.children/>
>>>                         </#if>
>>>                 </#foreach>
>>>         </#if>
>>> </#macro>
>>>
>>> Any reasons for the Error :-?
>>
>> Maybe the children field, when there are no children, is an empty list
>> instead of null?
> 
> Actually that would cause only one extra call... so it's not that.
> 
>> Or... you managed to create a loop in the object
>> graph?
>>
>>
> 
> -- 
> Best regards,
>  Daniel Dekany
> 
> 
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay 
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
> 
> 

-- 
View this message in context: http://www.nabble.com/Calling--Macro-Recursively-tp25902765p25906844.html
Sent from the freemarker-user mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.