PrimeFaces对话框的延迟加载(dynamic ="true")无法正常工作吗? [英] PrimeFaces dialog lazy loading (dynamic="true") does not work?

查看:133
本文介绍了PrimeFaces对话框的延迟加载(dynamic ="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

<ui:include>在视图构建期间作为标记处理程序运行,而渲染属性在视图呈现期间进行评估.

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. <ui:include>部分周围使用类似<c:if>的视图构建时间标签.
  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;
}

然后将<ui:include>括在<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:对话框ID p:commandButton更新 p:commandButton完成

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

这篇关于PrimeFaces对话框的延迟加载(dynamic ="true")无法正常工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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