Primefaces如何更新对话框中的内容并保持对话框居中? [英] Primefaces how to update content in a dialog and keep the dialog centered?

查看:187
本文介绍了Primefaces如何更新对话框中的内容并保持对话框居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话框,该对话框在页面加载时不包含任何内容,并且正在根据用户单击的链接来动态设置对话框的内容.

I have a dialog that contains no content on page load and I'm dynamically setting the content of a dialog box based on the link that a user clicks on.

<p:dialog widgetVar="dlg" modal="true" id="dialog">
    <p:panel id="fullArticle">
        <h:outputText value="#{content.newsArticle}" escape="false" />
    </p:panel>
 </p:dialog>
...
...
<p:commandLink value="Read more" actionListener="#{content.getFullArticle}" onclick='dlg.show();' update=":fullArticle">
    <f:attribute name="contentId" value="#{news.contentId}" />
</p:commandLink>

我遇到的问题是,当您单击阅读更多"链接时,它显示了对话框,但是对话框不在页面的中心.如果我将commandLink上的udpate属性更改为update=":dialog",该对话框将闪烁,就像打开并立即关闭一样.

The problem i'm having is that when you click the "Read More" link, it shows the dialog, but the dialog is not centered on the page. If i change the udpate attribute on the commandLink to update=":dialog", the dialog flashes as if it's opening and then closing right away.

如何更新对话框并将其置于动态内容的中心?

How can I update the dialog and have it be centered with dynamic content?

推荐答案

onclick是在ajax请求之前 执行的.您需要改为在oncomplete中打开对话框.该操作将在ajax请求后 执行并更新.除非<p:dialog>属性的值计算为true,否则默认情况下<p:dialog>即为隐藏状态.

The onclick is executed before the ajax request. You need to open the dialog in oncomplete instead. This will be executed after the ajax request and update. The <p:dialog> is namely by default hidden unless its visible attribute evaluates true.

<p:commandLink value="Read more" actionListener="#{content.getFullArticle}" 
    update=":dialog" oncomplete="dlg.show()">


无关与具体问题无关,您是否知道自EL 2.2起可以将有价值的对象作为方法参数传递?这使得<f:attribute>actionListener"hack"是多余的:


Unrelated to the concrete problem, are you aware that you can pass fullworthy objects as method arguments since EL 2.2? This makes the <f:attribute> and actionListener "hack" superfluous:

<p:commandLink value="Read more" action="#{content.getFullArticle(news)}" 
    update=":dialog" oncomplete="dlg.show()" />

这篇关于Primefaces如何更新对话框中的内容并保持对话框居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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