I want to dynamically pick a facelet to render some item in my data list. The first try would be:
<ui:repeat value="#{panels}" var="panel"> <ui:include src="#{panel.facelet}"> </ui:repeat>
But it won't work since src of ui:include is evaluated too early. The facelet information is truly dynamic, so I cannot use c:forEach (not really recommended to mix with facelets either). I guess it all boils down to finding a component based ui:include alternative.
Is there such thing or I need to write my own?
I think I've found that relatively simple solution you've been looking for.
I too started with a ui:include inside a ui:repeat like yours, but I accepted that I had to use a c:forEach, and the c:forEach worked great for dynamically getting a different set of xhtml/components to include even with user interaction changing things in the View like I think you have. It looked like this:
<c:forEach var="thing" items="#{view.things}">
<ui:include src="#{thing.renderComponent}">
<ui:param name="thing" value="#{thing}"/>
</ui:include>
</c:forEach>
However, my ui:param wasn't working - every component I included was passed the same "thing"/Object even though we had successfully used different things/Objects to dynamically include different components.
That's when I found this post which inspired me to wrap my ui:include in a f:subview. And now everything is working great with the following code:
<c:forEach var="thing" items="#{view.things}" varStatus="loop">
<f:subview id="thing_#{loop.index}">
<ui:include src="#{thing.renderComponent}">
<ui:param name="thing" value="#{thing}"/>
</ui:include>
</f:subview>
</c:forEach>
c:forEach will solve it, why can't you use it?
Interesting article regarding that issue: https://rogerkeays.com/jsf-c-foreach-vs-ui-repeat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With