且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PrimeFaces 对话框延迟加载(动态 =“true")不起作用?

更新时间:2023-10-02 11:03:40

找到了一些非常简单的解决方法:

have found some pretty easy workaround:

让我们引用 BalusC 在另一个问题上的回答:跳过执行<ui:include>当父 UI 组件未呈现时

Let's quote BalusC's answer on this other question: Skip executing <ui:include> when parent UI component is not rendered

在视图构建期间作为标记处理程序运行,而渲染属性在视图渲染期间进行评估.

The <ui:include> runs as being a taghandler during the view build time, while the rendered attribute is evaluated during the view render time.

关于他的第一个提议:

  1. 部分周围使用像 这样的视图构建时间标记.
  1. Use a view build time tag like <c:if> around the <ui:include> part.

因此,首先向您的 bean 添加一些新方法.(甚至可能在某些应用程序范围的 bean 中有用以供重用)

So first add some new method to your bean. (may even be useful in some application scoped bean for reuse)

public boolean isAjaxRequest() {
    boolean val = FacesContext.getCurrentInstance().getPartialViewContext().isAjaxRequest();
    return val;
}

然后将您的 包含在以下 中:

Then enclose your <ui:include> inside following <c:if>:

<p:dialog id="yourDlg" header="Dialog" widgetVar="dlgMultiFileSelect" modal="true" resizable="true" dynamic="true"> 
    <c:if test="#{applicationBean.ajaxRequest}">
        <ui:include src="/dialogs/media_browser.xhtml"/>
    </c:if>
</p:dialog>

因此,在页面加载时,请求不是 ajax ……而在基页上的其他 ajax 请求中,对话框不会更新……但是如果你触发你的对话

So at page load time, the request isn't ajax... and on other ajax requests on base page, the dialog won't be updated... But if you trigger your dialog

<p:commandButton id="addId" value="Add" title="Add" type="button" 
    oncomplete="dlgMultiFileSelect.show();" update=":yourDlg"/>

并更新它的内容,它最终会被渲染!

and update it's content, it will finally be rendered!

请注意以下更改:p:dialog idp:commandButton updatep:commandButton oncomplete

Please note following changes: The p:dialog id, p:commandButton update and p:commandButton oncomplete