Created
April 9, 2013 11:27
-
-
Save banterCZ/5344966 to your computer and use it in GitHub Desktop.
Using JSF, there is no nice way how to iterate over collection an include a template.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ui:composition template="/WEB-INF/templates/layout.xhtml" | |
xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:ui="http://java.sun.com/jsf/facelets" | |
xmlns:h="http://java.sun.com/jsf/html" | |
xmlns:c="http://java.sun.com/jstl/core"> | |
<ui:define name="content"> | |
<!-- does NOT work --> | |
<!-- JSTL tags are taghandlers and they are executed during view build time, while JSF UI components are executed during view render time --> | |
<!-- http://stackoverflow.com/a/3343681/204950 --> | |
<c:forEach var="item" items="#{items}"> | |
<h:panelGroup rendered="#{item.show}"> | |
<ui:include src="${item.template}" /> | |
</h:panelGroup> | |
</c:forEach> | |
<!-- does NOT work --> | |
<!-- <ui:include> runs during view build time (restore view phase) not during view render time (render response phase) --> | |
<!-- http://stackoverflow.com/a/13992285/204950 --> | |
<ui:repeat value="#{items}" var="item"> | |
<h:panelGroup rendered="#{item.show}"> | |
<ui:include src="${item.template}" /> | |
</h:panelGroup> | |
</ui:repeat> | |
<!-- works, but duplicity hell --> | |
<h:panelGroup rendered="#{items[0].show}"> | |
<ui:include src="#{items[0].template}" /> | |
</h:panelGroup> | |
<h:panelGroup rendered="#{items[1].show}"> | |
<ui:include src="#{items[1].template}" /> | |
</h:panelGroup> | |
<h:panelGroup rendered="#{items[2].show}"> | |
<ui:include src="#{items[2].template}" /> | |
</h:panelGroup> | |
</ui:define> | |
</ui:composition> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment