<p:dialog> 的渲染属性和可见属性之间的区别 [英] Difference between rendered and visible attributes of <p:dialog>
问题描述
我在我的项目中使用 PrimeFaces 3.2.我想知道设置
的 rendered 属性与设置 visible 属性.我应该什么时候使用这些属性中的任何一个?
I am using PrimeFaces 3.2 in my project. I wanted to know what is the difference between setting the rendered attribute of a <p:dialog>
as against setting the visible attribute. When should I use either of these attributes?
推荐答案
rendered
属性是服务器端的,而 visible
属性是客户端的.rendered
属性告诉 JSF 是否应该生成对话框的 HTML 表示.visible
属性告诉 HTML/CSS/JS 是否应该在浏览器页面加载时立即显示对话框.
The rendered
attribute is server-side and the visible
attribute is client-side. The rendered
attribute tells whether JSF should generate the dialog's HTML representation or not. The visible
attribute tells whether HTML/CSS/JS should immediately show the dialog on browser's page load or not.
如果对话框未呈现,则您将无法通过例如 JavaScript dialogWidgetVar.show()
显示它,而无需重新加载页面或 ajax 更新对话框的父级之一组件,以便对话框的 rendered
条件评估为 true
.此外,如果对话框没有被渲染,visible
属性也不会产生任何影响,因为没有任何内容渲染到结果 HTML 输出中,可以通过 JavaScript 显示/隐藏.
If the dialog isn't rendered, then you won't be able to display it by for example JavaScript dialogWidgetVar.show()
without reloading the page or ajax-updating one of the dialog's parent components that way so that the dialog's rendered
condition evaluates to true
. Also the visible
attribute won't have any effect if the dialog is not rendered simply because there's nothing being rendered to the resulting HTML output which could be shown/hidden by JavaScript.
如果对话框被渲染,那么它默认是隐藏的.您可以将 visible
设置为 true
以强制它在打开页面时立即显示对话框.或者您可以在某些 onclick
或 oncomplete
属性中调用 JavaScript dialogWidgetVar.show()
来显示它.
If the dialog is rendered, then it is by default hidden. You can set visible
to true
to force it to display the dialog immediately whenever the page is opened. Or you can invoke JavaScript dialogWidgetVar.show()
in some onclick
or oncomplete
attribute to show it.
如果您根本不想渲染对话框,请使用 rendered
属性,例如因为它永远不会在当前请求的页面组合中使用.
Use the rendered
attribute if you don't want to render the dialog at all, for example because it wouldn't ever be used anyway in the currently requested page composition.
这篇关于<p:dialog> 的渲染属性和可见属性之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!