I have a dynamic dialog
<p:dialog
dynamic="true"
closeOnEscape="true"
id="modalID"
modal="true"
>
<p:outputPanel rendered="#{empty testBean.someArrayList}">
empty
</p:outputPanel>
</p:dialog>
When I include this dialog on a page the testBean is not initialized - great, that is what I want. It is only initialized when I show the dialog.
However when I include a p:dataTable in the dialog:
<p:dialog
dynamic="true"
closeOnEscape="true"
id="modalID"
modal="true"
>
<p:outputPanel>
<p:dataTable rendered="#{not empty testBean.someArrayList}" value="#{testBean.someArrayList}" var="item">
<p:column>
#{item}
</p:column>
</p:dataTable>
</p:outputPanel>
</p:dialog>
The testBean is being initialised and testBean.getSomeArrayList() is called on the backing bean. I have read that this is the case with ui:includes (see Launching dialogs using PrimeFaces via <p:dialog> and <ui:include>) but why is that the case with a p:dataTable? Btw. putting a rendered around the p:dataTable didn't fix the problem either.
What options do I have to not have testBean initialised straight away? I could use c:if but from my experience you can get strange results when you mix JSTL and JSF. I normally only use it to exclude stuff that will not be rendered (even after some ajax requests). When I used it before with ajax it did sort of worked but could cause unexpected problems.
Another option I could see is to use ui:include with dynamic src e.g.
<p:dialog
dynamic="true"
closeOnEscape="true"
id="modalID"
modal="true"
>
<p:outputPanel id="updateMeWhenOpeningModal">
<ui:insert src="#{dialogManager.testBeanSrc}"/>
</p:outputPanel>
</p:dialog>
And then change the testBeanSrc from path to an empty file to a file containing the p:dataTable.
Are there any other solutions? Which one would have the least side effects?