Re: Calling #Macro Recursively
Jeremy Chone <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
BTW, I am using template recursion in many of my templates and it worked just fine. So, might be your specific logic somewhere. On Thu, Oct 15, 2009 at 5:37 AM, Daniel Dekany <[email protected]> wrote: > Thursday, October 15, 2009, 1:18:13 PM, rizzz86 wrote: > > > 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. > > Then, as I said, maybe you indeed messed up the object graph in the > data-model. Check your *Java* code. It's hardly a FreeMarker problem. > > > 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: > > Look, if you think there is a bug regarding recursion or parameter > names (improbable), construct a self-containing minimal example, and > post that. Now I just can't know what did you mess up where, that may > lead you to false conclusions regarding what matters and what doesn't. > Like, there is nothing special in recursion; when a method calls > itself, the same rules apply as if you call another method. It's not a > special case. > > > 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 > >> > >> > > > > -- > 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 > -- Jeremy Chone +1 415 699 9912 CTO, VP Product Development and Operations, www.iJuris.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 _______________________________________________ FreeMarker-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/freemarker-user