Discussion:
[FreeMarker-user] Calling #Macro Recursively
rizzz86
2009-10-15 03:59:05 UTC
Permalink
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).

<#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 :-?
--
View this message in context: http://www.nabble.com/Calling--Macro-Recursively-tp25902765p25902765.html
Sent from the freemarker-user mailing list archive at Nabble.com.
rizzz86
2009-10-15 04:00:35 UTC
Permalink
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 :-?
--
View this message in context: http://www.nabble.com/Calling--Macro-Recursively-tp25902765p25902765.html
Sent from the freemarker-user mailing list archive at Nabble.com.
rizzz86
2009-10-15 04:01:51 UTC
Permalink
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>
< span class="folder">< a
href="${element.url}">${element.title}</ a></ span>..... // Generates Menu
<#if element.children??>
<@menugenerator menuList=element.children/>
</#if>
</#foreach>
</#if>
</#macro>

Any reasons for the Error :-?
--
View this message in context: http://www.nabble.com/Calling--Macro-Recursively-tp25902765p25902765.html
Sent from the freemarker-user mailing list archive at Nabble.com.
Daniel Dekany
2009-10-15 10:52:31 UTC
Permalink
Post by rizzz86
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.
class MenuBean {
String title;
String url;
List<MenuBean> children;
etc..
}
I can have N numbers of children for each menu (no limit).
<#macro menugenerator menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if 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? Or... you managed to create a loop in the object
graph?
--
Best regards,
Daniel Dekany
Daniel Dekany
2009-10-15 10:57:57 UTC
Permalink
Post by Daniel Dekany
Post by rizzz86
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.
class MenuBean {
String title;
String url;
List<MenuBean> children;
etc..
}
I can have N numbers of children for each menu (no limit).
<#macro menugenerator menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if 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.
Post by Daniel Dekany
Or... you managed to create a loop in the object
graph?
--
Best regards,
Daniel Dekany
rizzz86
2009-10-15 11:18:13 UTC
Permalink
What more I have found is that the parameter of the macro (i.e. menuList)
might be creating a problem.
Post by Daniel Dekany
<#macro menugenerator1 menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if element.children??>
</#if>
</#foreach>
</#if>
</#macro>
<#macro menugenerator2 menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if 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
Post by Daniel Dekany
Post by rizzz86
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.
class MenuBean {
String title;
String url;
List<MenuBean> children;
etc..
}
I can have N numbers of children for each menu (no limit).
<#macro menugenerator menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if 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
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.
Daniel Dekany
2009-10-15 12:37:31 UTC
Permalink
Post by rizzz86
What more I have found is that the parameter of the macro (i.e. menuList)
might be creating a problem.
Post by Daniel Dekany
<#macro menugenerator1 menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if element.children??>
</#if>
</#foreach>
</#if>
</#macro>
<#macro menugenerator2 menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if 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.
Post by rizzz86
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
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.
Post by rizzz86
rizzz86
Post by Daniel Dekany
Post by rizzz86
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.
class MenuBean {
String title;
String url;
List<MenuBean> children;
etc..
}
I can have N numbers of children for each menu (no limit).
<#macro menugenerator menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if 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
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Best regards,
Daniel Dekany
Jeremy Chone
2009-10-15 16:06:09 UTC
Permalink
BTW, I am using template recursion in many of my templates and it worked
just fine. So, might be your specific logic somewhere.
Post by rizzz86
Post by rizzz86
What more I have found is that the parameter of the macro (i.e. menuList)
might be creating a problem.
I have created two macros "menugenerator1" and "menugenerator2" as
Post by Daniel Dekany
<#macro menugenerator1 menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if element.children??>
menuList=element.children/>
Post by rizzz86
Post by Daniel Dekany
</#if>
</#foreach>
</#if>
</#macro>
<#macro menugenerator2 menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if element.children??>
menuList=element.children/>
Post by rizzz86
Post by Daniel Dekany
</#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.
Post by rizzz86
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
Post by rizzz86
in macro 2 (i.e. element.children).
Now what i am thinking is that how can I call the recursive macro with
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.
Post by rizzz86
rizzz86
Post by Daniel Dekany
Post by rizzz86
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.
class MenuBean {
String title;
String url;
List<MenuBean> children;
etc..
}
I can have N numbers of children for each menu (no limit).
<#macro menugenerator menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if element.children??>
menuList=element.children/>
Post by rizzz86
Post by Daniel Dekany
Post by rizzz86
</#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
------------------------------------------------------------------------------
Post by rizzz86
Post by 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
Post by rizzz86
Post by Daniel Dekany
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
FreeMarker-user mailing list
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
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Jeremy Chone
+1 415 699 9912
CTO, VP Product Development and Operations,
www.iJuris.com
rizzz86
2009-10-16 09:30:34 UTC
Permalink
Thanks for reply.
I am working looking at my Java code now.
Post by Jeremy Chone
BTW, I am using template recursion in many of my templates and it worked
just fine. So, might be your specific logic somewhere.
Post by rizzz86
Post by rizzz86
What more I have found is that the parameter of the macro (i.e.
menuList)
Post by rizzz86
might be creating a problem.
I have created two macros "menugenerator1" and "menugenerator2" as
Post by Daniel Dekany
<#macro menugenerator1 menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if element.children??>
menuList=element.children/>
Post by rizzz86
Post by Daniel Dekany
</#if>
</#foreach>
</#if>
</#macro>
<#macro menugenerator2 menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if element.children??>
menuList=element.children/>
Post by rizzz86
Post by Daniel Dekany
</#if>
</#foreach>
</#if>
</#macro>
If I call 2nd macro inside first macro (as shown) ... the 2nd macro
will
Post by rizzz86
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
Post by rizzz86
(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.
Post by rizzz86
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
Post by rizzz86
in macro 2 (i.e. element.children).
Now what i am thinking is that how can I call the recursive macro with
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.
Post by rizzz86
rizzz86
Post by Daniel Dekany
Post by rizzz86
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.
class MenuBean {
String title;
String url;
List<MenuBean> children;
etc..
}
I can have N numbers of children for each menu (no limit).
<#macro menugenerator menuList>
<#if menuList??>
<#foreach element in menuList>
${element.url} ${element.title} ..... // Generates
Menu
<#if element.children??>
menuList=element.children/>
Post by rizzz86
Post by Daniel Dekany
Post by rizzz86
</#if>
</#foreach>
</#if>
</#macro>
Any reasons for the Error :-?
Maybe the children field, when there are no children, is an empty
list
Post by rizzz86
Post by Daniel Dekany
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
------------------------------------------------------------------------------
Post by rizzz86
Post by 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
Post by rizzz86
Post by Daniel Dekany
developing skills, take BlackBerry mobile applications to market and
stay
Post by rizzz86
Post by Daniel Dekany
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
FreeMarker-user mailing list
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
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
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
View this message in context: http://www.nabble.com/Calling--Macro-Recursively-tp25902765p25922429.html
Sent from the freemarker-user mailing list archive at Nabble.com.
firoza
2014-10-16 17:33:52 UTC
Permalink
Hi,
Did we get the solution for the problem?

I am having the same requirement for recursion.
Below is the scenario:

HierarchyView - class

Name
Conf
Material Number
List<HierarchyView> children

I have list of HierarchyView and n level of HierarchyView children under
each object. How could I iterate that in ftl?
Please help.

Thanks



--
View this message in context: http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655293.html
Sent from the freemarker-user mailing list archive at Nabble.com.
Daniel Dekany
2014-10-16 22:47:34 UTC
Permalink
No FreeMarker-related problem was described in the original thread, as
far as I see. Do you have any specific problem?
Post by firoza
Hi,
Did we get the solution for the problem?
I am having the same requirement for recursion.
HierarchyView - class
Name
Conf
Material Number
List<HierarchyView> children
I have list of HierarchyView and n level of HierarchyView children under
each object. How could I iterate that in ftl?
Please help.
Thanks
--
http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655293.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
FreeMarker-user mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Thanks,
Daniel Dekany
firoza
2014-10-18 07:42:53 UTC
Permalink
Hi,
I have the requirement to display the recursive objects in ftl.
I am not sure whether using macro is the right option and as per the
original thread It didn't mention that we got the solution for such kind of
requirement.
Would you please check my last post where I have mentioned my requirement
for displaying the recursive list in ftl?

Any help would be highly appreciated.

Thanks



--
View this message in context: http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655295.html
Sent from the freemarker-user mailing list archive at Nabble.com.
Daniel Dekany
2014-10-18 19:12:56 UTC
Permalink
Write a macro that expects a List<HierarchyView> as argument, and
walks it using #list (just the top level). Inside the #list, after
printing the current item *without* its List<HierarchyView> child, the
macro should call itself by passing that child list in as the
argument. That's the basic idea.

Each macros call has its own local scope, so they won't interfere with
other ongoing macro calls. But don't forget that to set variables in
the local scope, #local must be used, not #assign. (Macro arguments
and the #list loop variables is always local.)
Post by firoza
Hi,
I have the requirement to display the recursive objects in ftl.
I am not sure whether using macro is the right option and as per the
original thread It didn't mention that we got the solution for such kind of
requirement.
Would you please check my last post where I have mentioned my requirement
for displaying the recursive list in ftl?
Any help would be highly appreciated.
Thanks
--
http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655295.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
FreeMarker-user mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Thanks,
Daniel Dekany
firoza
2014-10-19 15:16:51 UTC
Permalink
Thanks Deniel for your quick response.
I tired with the approach you suggested but it is not displaying any
information on the page.

Below is the code snipped:

HierarchyProductSearchResult{
private Integer chpd;
private Integer conf;
private String link;
private List<String> activeName = Collections.emptyList();
private List<String> inactiveName= Collections.emptyList();
private List<HierarchyProductSearchResult> children =
Collections.emptyList();
}

I have a service method which returns list of HierarchyProductSearchResult.
That list is productSearchResultList.

In ftl I have created the macro and iterating the loop. Blow is the code in
ftl for macro:

<ul class="accordion">
<#macro hierarchy productSearchResultList>

<#list productSearchResultList as productresult>

<#assign detailViewPopUp="Y">
<li>


<#if productresult.children?has_content>
<@liferay_ui.message key="resultview.hierarchy.click"/>
<JavaScript:void(0);>

</#if>



<#include "include/resultRecordDetails.ftl" >

<#if productresult.children?has_content>
<ul>

<@hierarchy productSearchResultList=productresult.children/>
</ul>

</#if>

</li>

</#list>
</#macro>



Would you please let me know where I am making the mistake? I got stuck in
this.

Thanks





--
View this message in context: http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655297.html
Sent from the freemarker-user mailing list archive at Nabble.com.
Daniel Dekany
2014-10-19 16:05:25 UTC
Permalink
FTL only sees public members of public classes. Furthermore with it
default configuration it won't try to read fields, only JavaBean
properties. That is, you need getter methods, as usual in Java.
Post by firoza
Thanks Deniel for your quick response.
I tired with the approach you suggested but it is not displaying any
information on the page.
HierarchyProductSearchResult{
private Integer chpd;
private Integer conf;
private String link;
private List<String> activeName = Collections.emptyList();
private List<String> inactiveName= Collections.emptyList();
private List<HierarchyProductSearchResult> children =
Collections.emptyList();
}
I have a service method which returns list of HierarchyProductSearchResult.
That list is productSearchResultList.
In ftl I have created the macro and iterating the loop. Blow is the code in
<ul class="accordion">
<#macro
hierarchy productSearchResultList>
<#list
productSearchResultList as productresult>
<#assign detailViewPopUp="Y">
<li>
<#if productresult.children?has_content>
<JavaScript:void(0);>
</#if>
<#include "include/resultRecordDetails.ftl" >
<#if productresult.children?has_content>
<ul>
</ul>
</#if>
</li>
</#list>
</#macro>
Would you please let me know where I am making the mistake? I got stuck in
this.
Thanks
--
http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655297.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
FreeMarker-user mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Thanks,
Daniel Dekany
Firoza Saiyed
2014-10-20 03:07:18 UTC
Permalink
Yes Daniel, I have getter and setters both in my pojo. And I am using
liferay + freemarker. Setting the list from controller and want to use
it on ftl. This is an Arraylist which holds pojos of the type
HierarchyProductSearchResult. If I just iterate with list tag of ftl
for first level (without macro) I am getting the results displayed on
the screen but for recursive call with maco no contents are displayed.

Thanks

Sent from my Windows Phone From: Daniel Dekany
Sent: ‎19-‎10-‎2014 09:35 PM
To: firoza
Cc: freemarker-***@lists.sourceforge.net
Subject: Re: [FreeMarker-user] Calling #Macro Recursively
FTL only sees public members of public classes. Furthermore with it
default configuration it won't try to read fields, only JavaBean
properties. That is, you need getter methods, as usual in Java.
Post by firoza
Thanks Deniel for your quick response.
I tired with the approach you suggested but it is not displaying any
information on the page.
HierarchyProductSearchResult{
private Integer chpd;
private Integer conf;
private String link;
private List<String> activeName = Collections.emptyList();
private List<String> inactiveName= Collections.emptyList();
private List<HierarchyProductSearchResult> children =
Collections.emptyList();
}
I have a service method which returns list of HierarchyProductSearchResult.
That list is productSearchResultList.
In ftl I have created the macro and iterating the loop. Blow is the code in
<ul class="accordion">
<#macro
hierarchy productSearchResultList>
<#list
productSearchResultList as productresult>
<#assign detailViewPopUp="Y">
<li>
<#if productresult.children?has_content>
<JavaScript:void(0);>
</#if>
<#include "include/resultRecordDetails.ftl" >
<#if productresult.children?has_content>
<ul>
</ul>
</#if>
</li>
</#list>
</#macro>
Would you please let me know where I am making the mistake? I got stuck in
this.
Thanks
--
http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655297.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
FreeMarker-user mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Thanks,
Daniel Dekany
Daniel Dekany
2014-10-20 17:14:29 UTC
Permalink
Do call that "hierarchy" macro somewhere outside the macro itself?
Because I see #macro after the <ul>, which is a rather unusual
placement for macro definition. #macro just defines a macro, you also
have to call it to generate output.
Post by Firoza Saiyed
Yes Daniel, I have getter and setters both in my pojo. And I am using
liferay + freemarker. Setting the list from controller and want to use
it on ftl. This is an Arraylist which holds pojos of the type
HierarchyProductSearchResult. If I just iterate with list tag of ftl
for first level (without macro) I am getting the results displayed on
the screen but for recursive call with maco no contents are displayed.
Thanks
Sent from my Windows Phone From: Daniel Dekany
Sent: ‎19-‎10-‎2014 09:35 PM
To: firoza
Subject: Re: [FreeMarker-user] Calling #Macro Recursively
FTL only sees public members of public classes. Furthermore with it
default configuration it won't try to read fields, only JavaBean
properties. That is, you need getter methods, as usual in Java.
Post by firoza
Thanks Deniel for your quick response.
I tired with the approach you suggested but it is not displaying any
information on the page.
HierarchyProductSearchResult{
private Integer chpd;
private Integer conf;
private String link;
private List<String> activeName = Collections.emptyList();
private List<String> inactiveName= Collections.emptyList();
private List<HierarchyProductSearchResult> children =
Collections.emptyList();
}
I have a service method which returns list of HierarchyProductSearchResult.
That list is productSearchResultList.
In ftl I have created the macro and iterating the loop. Blow is the code in
<ul class="accordion">
<#macro
hierarchy productSearchResultList>
<#list
productSearchResultList as productresult>
<#assign detailViewPopUp="Y">
<li>
<#if productresult.children?has_content>
<JavaScript:void(0);>
</#if>
<#include "include/resultRecordDetails.ftl" >
<#if productresult.children?has_content>
<ul>
</ul>
</#if>
</li>
</#list>
</#macro>
Would you please let me know where I am making the mistake? I got stuck in
this.
Thanks
--
http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655297.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
FreeMarker-user mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Thanks,
Daniel Dekany
firoza
2014-10-23 17:43:00 UTC
Permalink
Hi Deniel,
I tried for recursive call but its not working it's giving errors at
runtime.

Below is what i want to achieve:
I have a Java Bean (pojo) with followin fields with getter and setter
methods.

The pojos are populated with data using the recursive function of java.

I have productSearchResultList bject which is the list of type
HierarchyProductSearchResult(which is populated as metioned above).
Now I want to display this list in ftl

The format is :
//Iterate the productSearchResultList and if the recods has children then
open the new ul and display all its children in li.. This will go till n
level
<ul>
<li>


//this entry has children
<ul>
<li>
<ul>
<li></li>
</ul>
</li>
<li></li>
<li></li>
</ul>
</li>

<li></li>
...
</ul>

In each <li> I need to dispaly the infomation in a table something like this



${productresult.chpd}

${productresult.conf}

${productresult.conf}



The code in FTL:

<div class="col-results">

<#macro hierarchy searchResultList>
<ul>
<#list searchResultList as productresult>

<#assign detailViewPopUp="Y">
<li>


<#if productresult.hierarchy.children?has_content>
<@liferay_ui.message key="resultview.hierarchy.click"/>
<JavaScript:void(0);>

</#if>





${productresult.chpd}

${productresult.conf}
........





<#if productresult.hierarchy.children?has_content>


<@hierarchy searchResultList=productresult.hierarchy.children/>


</#if>

</li>

</#list>
</ul>
</#macro>

<@hierarchy searchResultList=productSearchResultList/>

</div>


Please let me know where I am making the mistake. I got stuck in this.

Thanks,
Firoza



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

------------------------------------------------------------------------------
Daniel Dekany
2014-10-23 18:05:32 UTC
Permalink
I don't believe that solving this problem involves any advanced
FreeMarker features. It's just generic algorithm writing. Thus, if you
have a *minimal* example that demonstrates an aspect of FreeMarker
that you don't get, please post that. Also, when your problem involves
an error, always include the error message.
Post by firoza
Hi Deniel,
I tried for recursive call but its not working it's giving errors at
runtime.
I have a Java Bean (pojo) with followin fields with getter and setter
methods.
The pojos are populated with data using the recursive function of java.
I have productSearchResultList bject which is the list of type
HierarchyProductSearchResult(which is populated as metioned above).
Now I want to display this list in ftl
//Iterate the productSearchResultList and if the recods has children then
open the new ul and display all its children in li.. This will go till n
level
<ul>
<li>
//this entry has children
<ul>
<li>
<ul>
<li></li>
</ul>
</li>
<li></li>
<li></li>
</ul>
</li>
<li></li>
...
</ul>
In each <li> I need to dispaly the infomation in a table something like this
${productresult.chpd}
${productresult.conf}
${productresult.conf}
<div class="col-results">
<#macro hierarchy searchResultList>
<ul>
<#list
searchResultList as productresult>
<#assign detailViewPopUp="Y">
<li>
<#if productresult.hierarchy.children?has_content>
<JavaScript:void(0);>
</#if>
${productresult.chpd}
${productresult.conf}
........
<#if productresult.hierarchy.children?has_content>
</#if>
</li>
</#list>
</ul>
</#macro>
</div>
Please let me know where I am making the mistake. I got stuck in this.
Thanks,
Firoza
--
http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655304.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
FreeMarker-user mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Thanks,
Daniel Dekany


------------------------------------------------------------------------------
Daniel Dekany
2014-10-23 19:53:09 UTC
Permalink
So I guess productresult.hierarchy.children?has_content returns false,
does it? In Java, do you have something like
HierarchyProductSearchResult.getHierarchy().getChildren() that's all
public in public classes and returns non-null.
Hi Daniel,
Yes there was some null check needed which i did and i could now see
the results being displayed but now the problem is it just displays the
first level hierarchy. It doesn't continue till n level though we have
data so still the problem is not resolved.
Sent from my Windows Phone From: Daniel Dekany
Sent: ‎23-‎10-‎2014 11:35 PM
To: firoza
Subject: Re: [FreeMarker-user] Calling #Macro Recursively
I don't believe that solving this problem involves any advanced
FreeMarker features. It's just generic algorithm writing. Thus, if you
have a *minimal* example that demonstrates an aspect of FreeMarker
that you don't get, please post that. Also, when your problem involves
an error, always include the error message.
Post by firoza
Hi Deniel,
I tried for recursive call but its not working it's giving errors at
runtime.
I have a Java Bean (pojo) with followin fields with getter and setter
methods.
The pojos are populated with data using the recursive function of java.
I have productSearchResultList bject which is the list of type
HierarchyProductSearchResult(which is populated as metioned above).
Now I want to display this list in ftl
//Iterate the productSearchResultList and if the recods has children then
open the new ul and display all its children in li.. This will go till n
level
<ul>
<li>
//this entry has children
<ul>
<li>
<ul>
<li></li>
</ul>
</li>
<li></li>
<li></li>
</ul>
</li>
<li></li>
...
</ul>
In each <li> I need to dispaly the infomation in a table something like this
${productresult.chpd}
${productresult.conf}
${productresult.conf}
<div class="col-results">
<#macro hierarchy searchResultList>
<ul>
<#list
searchResultList as productresult>
<#assign detailViewPopUp="Y">
<li>
<#if productresult.hierarchy.children?has_content>
<JavaScript:void(0);>
</#if>
${productresult.chpd}
${productresult.conf}
........
<#if productresult.hierarchy.children?has_content>
</#if>
</li>
</#list>
</ul>
</#macro>
</div>
Please let me know where I am making the mistake. I got stuck in this.
Thanks,
Firoza
--
http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655304.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
FreeMarker-user mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Thanks,
Daniel Dekany


------------------------------------------------------------------------------
firoza
2014-10-24 06:34:52 UTC
Permalink
Also all the fields are in public class. But these fields are private and we
have public getter and setter methods for each field. I think that is the
java bean standard and won't be an issue.
Children field is initialized to empty collection by default but hierarchy
field is not initialized so it will take null default value. So I am
checking for null for hierarchy and for null for its children before calling
the macro.

Firoza



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

------------------------------------------------------------------------------
Daniel Dekany
2014-10-24 08:21:58 UTC
Permalink
There's some oversight there. Can you post a minimized and well
readable, but *actually executed* template and model class code, with
its output?
Post by firoza
Also all the fields are in public class. But these fields are private and we
have public getter and setter methods for each field. I think that is the
java bean standard and won't be an issue.
Children field is initialized to empty collection by default but hierarchy
field is not initialized so it will take null default value. So I am
checking for null for hierarchy and for null for its children before calling
the macro.
Firoza
--
http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655308.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
FreeMarker-user mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Thanks,
Daniel Dekany


------------------------------------------------------------------------------
Firoza Saiyed
2014-10-24 04:11:20 UTC
Permalink
Yes Daniel,
First i am checking for productresult.hierarchy?has_content &&
productresult.hierarchy.children?has_content and then calling the macro
<@hierarchy searchResultList=productresult.hierarchy.children />

And i have printed the the complete hierarchy object in controller
before sending to ftl and i could see the hierarchy correctly populated
but that is not getting displayed on ftl.

Firoza

Sent from my Windows Phone From: Daniel Dekany
Sent: ‎24-‎10-‎2014 01:23 AM
To: Firoza Saiyed
Cc: freemarker-***@lists.sourceforge.net
Subject: Re: [FreeMarker-user] Calling #Macro Recursively
So I guess productresult.hierarchy.children?has_content returns false,
does it? In Java, do you have something like
HierarchyProductSearchResult.getHierarchy().getChildren() that's all
public in public classes and returns non-null.
Hi Daniel,
Yes there was some null check needed which i did and i could now see
the results being displayed but now the problem is it just displays the
first level hierarchy. It doesn't continue till n level though we have
data so still the problem is not resolved.
Sent from my Windows Phone From: Daniel Dekany
Sent: ‎23-‎10-‎2014 11:35 PM
To: firoza
Subject: Re: [FreeMarker-user] Calling #Macro Recursively
I don't believe that solving this problem involves any advanced
FreeMarker features. It's just generic algorithm writing. Thus, if you
have a *minimal* example that demonstrates an aspect of FreeMarker
that you don't get, please post that. Also, when your problem involves
an error, always include the error message.
Post by firoza
Hi Deniel,
I tried for recursive call but its not working it's giving errors at
runtime.
I have a Java Bean (pojo) with followin fields with getter and setter
methods.
The pojos are populated with data using the recursive function of java.
I have productSearchResultList bject which is the list of type
HierarchyProductSearchResult(which is populated as metioned above).
Now I want to display this list in ftl
//Iterate the productSearchResultList and if the recods has children then
open the new ul and display all its children in li.. This will go till n
level
<ul>
<li>
//this entry has children
<ul>
<li>
<ul>
<li></li>
</ul>
</li>
<li></li>
<li></li>
</ul>
</li>
<li></li>
...
</ul>
In each <li> I need to dispaly the infomation in a table something like this
${productresult.chpd}
${productresult.conf}
${productresult.conf}
<div class="col-results">
<#macro hierarchy searchResultList>
<ul>
<#list
searchResultList as productresult>
<#assign detailViewPopUp="Y">
<li>
<#if productresult.hierarchy.children?has_content>
<JavaScript:void(0);>
</#if>
${productresult.chpd}
${productresult.conf}
........
<#if productresult.hierarchy.children?has_content>
</#if>
</li>
</#list>
</ul>
</#macro>
</div>
Please let me know where I am making the mistake. I got stuck in this.
Thanks,
Firoza
--
http://freemarker.624813.n4.nabble.com/Calling-Macro-Recursively-tp626735p4655304.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
FreeMarker-user mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Thanks,
Daniel Dekany

------------------------------------------------------------------------------
Loading...