PrimeFaces 对话框延迟加载(动态 =“true")不起作用? [英] PrimeFaces dialog lazy loading (dynamic="true") does not work?

查看:33
本文介绍了PrimeFaces 对话框延迟加载(动态 =“true")不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将所有 bean 从 RequestScoped 更改为 ViewScoped.突然,对话框的延迟加载不起作用.我正在使用 PrimeFaces JSF 库.

I have recently changed all my beans from RequestScoped to ViewScoped. Suddenly, the lazy loading of dialogs does not work. I am using PrimeFaces JSF library.

<html>
<h:body>
<f:view>    
    <h:form>
        <p:commandButton id="addId" value="Add" title="Add" type="button" onclick="dlgMultiFileSelect.show();"/>
        ...
    </h:form>    
    <p:dialog header="Dialog" widgetVar="dlgMultiFileSelect" modal="true" resizable="true" dynamic="true"> 
        <ui:include src="/dialogs/media_browser.xhtml"/>
    </p:dialog>
</f:view>   
</h:body>
</html>

似乎 dynamic="true" 不起作用,因为 media_browser.xhtml 中的支持 bean 立即初始化,而不是在单击按钮时初始化.

Seems like dynamic="true" does not work since the backing bean in media_browser.xhtml gets initialized immediately, and not when button is clicked.

我做错了吗?

使用 PrimeFaces 3.5.0.

Using PrimeFaces 3.5.0.

推荐答案

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

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

这篇关于PrimeFaces 对话框延迟加载(动态 =“true")不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆