I always get a StackOverflowError
Then you've surely arrived at the right site now ;)
Jokes aside, composite components unfortunately do not support recursion. At my work we recently worked on a component that had similar requirements, and the way we solved it was to replace direct recursion with several Java based components that can be placed on a composite component to declare the recursive structure.
I can't give the actual code as it's copyrighted by my company, but the following is an example of how it could be used:
<jcf:recursion value="#{foo.someData}" var="item">
<jcf:recursionNode level="0">
<jcf:recursionNodeItem rendered="#{foo.someCondition}">
<!-- Some markup possibly referencing item -->
<jcf:insertRecursionNodeChildren />
<!-- Some more markup -->
</jcf:recursionNodeItem>
</jcf:recursionNode>
<jcf:recursionNode>
<!-- Some markup -->
<jcf:recursionNodeItem rendered="#{foo.someOtherCondition}">
<!-- Some more markup -->
<jcf:insertRecursionNodeChildren />
<!-- Some more markup -->
</jcf:recursionNodeItem>
<!-- Some more markup -->
</jcf:recursionNode>
</jcf:recursion>
The idea is that for each iteration of the recursion, one can define explicit markup and instructions. Shown in the example are instructions for the first level. If no level is defined, the instructions are for every level in the recursion that does not already have an explicit level defined. Nodes
denote new levels, while NodeItems
represent all items on a given level.
The parent Java based component then starts the actual recursion in Java code and delegates to its children for the rendering.
Hopefully this can get you going.