2

我正在为我的 Web UI 项目使用 PrimeFaces UI 库。

我有一个manage_watchfolder.xhtml有按钮的页面,这个按钮会启动一个对话框:

<p:commandButton value="Add" oncomplete="dlgEditWF.show()"
    update=":editWFForm" process="@none"/>  

在同一个文件中,我dlgEditWF包含了edit_watchfolder.xhtml

<p:dialog id="editDialog" widgetVar="dlgEditWF" modal="true"
    resizable="true" onShow="showHideActionLocation();">
    <ui:include src="edit/edit_watchfolder.xhtml"/>
</p:dialog> 

问题是我不想edit_watchfolder.xhtml在单击按钮之前加载。但是,在创建edit_watchfolder.xhtml的同时被“加载” manage_watchfolder.xhtml。因此,所有调用的 beanedit_watchfolder.xhtml都被创建、初始化等,甚至用户可能永远不会真正点击按钮。这会产生大量开销,并使执行速度变慢。

我可以避免这种情况吗?

4

2 回答 2

5

由于此答案中解释的原因,这是“设计使然”:Skip execution <ui:include> when parent UI component is not render

在您的特定情况下,您最好的选择是默认情况下保持 bean 未初始化,并在命令按钮的操作方法期间执行初始化。

<p:commandButton value="Add" action="#{bean.initDialog}" 
    process="@this" update=":editWFForm" oncomplete="dlgEditWF.show()" />
于 2013-02-14T19:12:43.067 回答
4

您可以使用 的“动态”属性p:dialog。查看 primefaces文档

<p:commandButton id="basic" value="Show Dialog" onclick="dlg.show();" type="button" />  

<p:dialog id="dialog" header="Dynamic Dialog" widgetVar="dlg" dynamic="true">  
    <h:outputText value="This content is loaded lazy." />  
</p:dialog>  
于 2013-02-18T20:23:32.877 回答