I will not paste my beans and model classes because there is everything ok with code. Problem is that first loop (ui:repeat) in dashboard.xhtml works fine but second loop (c:forEach) in comments.xhtml is not working.
I tested that #{comment.listComments.size()} in comments.xhtml really returns greater than zero which means that the c:forEach loop HAVE TO go through comments at least one time but it does not happening.
Dashboard.xhtml
<h:dataTable id="commentout" value="#{messageBean.getComments(msg)}" var="com" rendered="#{not empty messageBean.getComments(msg)}">
<h:column>
<div>
<b><i>#{com.owner.firstName} #{com.owner.lastName}:</i></b>
<h:outputText value=" #{com}" />
<h:commandLink style="margin: 0 0 0 10px; padding: 0;" styleClass="add_comment" value="Answer" action="#{commentBean.createCommentOnComment(com)}" />
</div>
<ui:repeat value="#{com.listComments}" var="comment" rendered="#{com.hasChildren}">
<ui:include src="comments.xhtml" />
</ui:repeat>
</h:column>
</h:dataTable>
comments.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<div style="margin-left: 20px;">
<div>
<b><i>>#{comment.owner.firstName} #{comment.owner.lastName}:</i></b>
<h:outputText value=" #{comment}" />
<h:commandLink style="margin: 0 0 0 10px; padding: 0;" styleClass="add_comment" value="Answer" action="#{commentBean.createCommentOnComment(comment)}" />
</div>
<c:when test="#{comment.hasChildren}">
#{comment.listComments.size()} <!-- Visual test for checking if it is really greater than zero -->
<c:forEach items="#{comment.listComments}" var="comment">
<ui:include src="comments.xhtml" />
</c:forEach>
</c:when>
</div>
</ui:composition>
Visual Problem:
OR
If someone has any better idea of recursion method then it also can be an correct answer...
UPDATE:
If I change the <c:forEach />
to <ui:repeat />
and instead of using </c:when>
use "rendered" attribute, it stuck and gives me error "Overflow".
Why <ui:repeat />
with <ui:include />
in summary gives me Overflow error?