3

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?

Ben
  • 1,922
  • 3
  • 23
  • 37
  • Initialize the datatable with an empty list? – Kukeltje May 24 '18 at 18:31
  • I want to avoid that the bean is created in the first place, I am trying to reduce the memory footprint per user and we have a lot of these cases where beans are being created without ever been really used. – Ben May 25 '18 at 07:30
  • A sort of empty bean is 1k in memory, if you have 1000 simultaneous users that is 1MB. Even if you have 50 places, it still is 50MB. I Cannot imagine that being a problem. If the empty bean takes (way) more than this you have a design problem (e.g. not an empty list, not lazy loading things etc. The UI layer should not be the place to fix this. – Kukeltje May 25 '18 at 08:18
  • I agree. Problem is this is a stack grown over years which is using Seam. A lot of these beans inject (and create) other beans in turn and they often do some initialisation in the @Create method. – Ben May 25 '18 at 08:41
  • Some initialization is not wrong, but loading complete datasets often is not. Can't you change that (and in the mean time switch to cdi ;-))? If you can make a real [mcve] and try with the PF versions of 6.x (preferably 6.2) I'll see if I can investigate over the weekend. I'm not going to investigate PF 5.x versions... Abnd what **is** your current version btw Both PF and JSF (and impl (mojarra/myfaces) – Kukeltje May 25 '18 at 10:21

0 Answers0