Note that there are some explanatory texts on larger screens.

plurals
  1. POFaking Recursion in JSF
    primarykey
    data
    text
    <p>I'm trying to display a tree in JSF without hard-coding the depth of the tree I want to display. Maybe for one configuration I only want to show the leaves, maybe for another I want to show the leaves grouped by the nodes one level above them, etc. So for one configuration, it could be:</p> <p><b><ul> <li>Question 1</li> <li>Question 2</li> <li>Question 3</li> <li>Question 4</li> </ul> </b></p> <p>While for another configuration, the same underlying data structure could produce:</p> <p><b><ul> <li>Category 1:</li></p> <ul> <li>Question 1</li> <li>Question 2</li> </ul> <p><li>Category 2:</li></p> <ul> <li>Question 3</li> </ul> <p><li>Category 3:</li></p> <ul> <li>Question 4</li> </ul> <p></ul> </b></p> <p>With a hypothetical third configuration grouping the categories by super-categories, etc.</p> <p>I tried making a composite component that called itself recursively if the node had more children. I did this via <code>&lt;ui:fragment rendered="#{node.hasChildren}"&gt;</code> and -- surprise! -- this resulted in an infinite loop and a stack overflow.</p> <p>The project already has PrimeFaces installed, so I'm looking at PrimeFaces <code>Tree</code> and <code>TreeNode</code>. But that doesn't quite feel right; I don't want the tree nodes to be expandable in the user interface. I want everything to be fully expanded. I haven't gone too deeply down this rabbit hole so I suspect there may be a way to achieve this with <code>Tree</code>, but it feels like I'm going against the grain of what it's built to do.</p> <p>What's a good approach this problem?</p> <p><hr /> <b>Edit:</b> I'm trying to use &lt;tree> and &lt;treeNode>, but it's not working. My code looks like this:</p> <pre><code>&lt;p:tree value="#{cc.attrs.classification}" var="child"&gt; &lt;p:treeNode&gt; &lt;ui:fragment rendered="#{child.childCount &gt; 0}"&gt; [do node stuff] &lt;/ui:fragment&gt; &lt;ui:fragment rendered="#{child.childCount == 0}"&gt; [do leaf stuff] &lt;/ui:fragment&gt; &lt;/p:treeNode&gt; &lt;/p:tree&gt; </code></pre> <p>... where <code>classification</code> implements the <code>TreeNode</code> interface. This results in errors to the console complaining that <code>child</code> is of type String and therefore cannot do any of the interesting things I'm asking of it. What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload