JSF <ui:include> Recursion Causes java.lang.StackOverflowError

时间:2016-02-12 21:07:28

标签: java jsp jsf recursion facelets

I have, what I would assume, is a pretty common use case. We're rendering a simple "Comments" page using JSF on Wildfly 10.0. Each comment may have a parent comment, and child comments underneath it. Since there's no way to know ahead of time what the structure is, we'd like to create a JSF fragment and yoGGie ツ it recursively to render the contents. It would look something like this...

Main page:

<ui:include />

Comment Fragment:

<ul class="comments>
  <ui:repeat value="#{myObj.comments}" var="comment">
    <ui:include src="/WEB-INF/fragments/comment.xhtml">
      <ui:param name="comment" value="#{comment}" />
    </ui:include>
  </ui:repeat>
</ul>

However, when I run this code, the recursion seems to cause <li><h:outputText value="#{comment.text}"> <ui:fragment rendered="#{not empty comment.childComments}"> <ul class="comments"> <ui:repeat value="#{comment.childComments}" var="comment"> <ui:include src="/WEB-INF/fragments/comment.xhtml"> <ui:param name="comment" value="#{comment}" /> </ui:include> </ui:repeat> </ul> </ui:fragment> </li> , regardless of how many items there are. Additionally, we see a java.lang.StackOverflowError saying, javax.servlet.ServletException

Is there a reason why this recursive call results in this Exception? Is there a better way to accomplish this? I've tried using "Could not Resolve Variable [Overflow]" to iterate over the comments, however when I do this it does not appear to work in JSF. I've tried both the <c:forEach /> and http://xmlns.jcp.org/jsp/jstl/core namespaces for the taglib, but the http://java.sun.com/jsp/jstl/core tag doesn't seem to iterate over my objects. (That is, nothing is being rendered to the page)

Any help you can give would be GREATLY appreciated.

0 个答案:

没有答案