jsr372-experts@javaserverfaces-spec-public.java.net

[jsr372-experts] recursive use of a custom component

From: Michael Müller <michael.mueller_at_mueller-bruehl.de>
Date: Mon, 8 Feb 2016 17:42:18 +0100

Hi,

I defined a node element with a text, an URL, and a list of nodes. Using
JSF, this should be shown as a kind of menu or tree, which might be
expanded or collapsed.

I created a custom component "MenuNode" to handle the tree in a
recursive way.
Using ui:repeat, I allways get a stack overflow.
Using c:forEach together with c:if, I'll get the stack overflow every
time the parent node is expanded.

   <cc:interface>
     <cc:attribute name="parentNode"
class="org.mm.portallib.tree.MenuTreeNode"/>
   </cc:interface>

   <!-- IMPLEMENTATION -->
   <cc:implementation>
     <c:forEach items="#{cc.attrs.parentNode.children}" var="node"
varStatus="status" rendered="#{cc.attrs.parentNode.children.size() gt 0}">
       <div style="margin-left:16px;">
         <mm:MenuItem/>
         <c:if test="#{node.expanded}" id="SubNode#{status.index}">
           <mm:MenuNode parentNode="#{node}"/>
         </c:if>
       </div>
     </c:forEach>

   </cc:implementation>

It seems, JSF will analyze this structure independent from its data
content: The structure terminates after few levels, whilst the tree
build seems to run into an endless loop. Is this a bug, or does cc do
not support any recursion?

-- 
Herzliche Grüße - Best Regards,
Michael Müller
Brühl, Germany
blog.mueller-bruehl.de <http://blog.mueller-bruehl.de/>
it-rezension.de <http://it-rezension.de/>
@muellermi
Read my books
"Web Development with Java and JSF": https://leanpub.com/jsf
"Java Lambdas und (parallel) Streams" Deutsche Ausgabe: 
https://leanpub.com/lambdas-de
"Java Lambdas and (parallel) Streams" English edition: 
https://leanpub.com/lambdas