How to stop recursive composite component from including itself recursively

后端 未结 2 1089
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 03:36

Is it possible to have a JSF component that has ui:repeat and inside the repeat call the same component? It\'s because I\'m building tree of question:



        
2条回答
  •  孤城傲影
    2021-01-16 03:48

    Use a view build time tag to stop the recursion instead of a view render time tag. The component tree is built during view build time. The rendered attribute isn't evaluated during view build time, but instead during view render time. So your construct basically keeps including itself in an infinite loop. You should already know that StackOverflowError is caused by a recursion so deep that the memory stack can't handle it anymore (usually around ~1000 iterations).

    Replace by a and it'll work as expected. The renderQuestions can by the way be simplified by omitting the check on children. The won't render anything anyway if there are no children.

    If you happen to use view scoped beans in this construct and you're using Mojarra implementation, then make sure that you upgrade to at least 2.1.18, because binding a view build time tag attribute to a view scoped bean property would in older versions break the view scope.

    See also:

    • JSTL in JSF2 Facelets... makes sense? - explains "view build time" versus "view render time"

提交回复
热议问题