打开页面时如何打开对话框 [英] How can I open a dialog when the page is opened

查看:29
本文介绍了打开页面时如何打开对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的一个页面中,我们有一个搜索按钮,可以打开一个搜索对话框,以便用户可以从远程系统搜索和导入一些数据.

In one of our page we have a search button that open a search dialog so that the users can search and import some data from a remote system.

现在有了新的要求,每次打开页面时都必须显示相同的对话框 - 但仅当页面将用于创建新注册表时,在更新模式下,只有当用户单击按钮.

Now got I new requirement that this same dialog must be showed every time the page is opened - but only when the page will be used to create a new registry, in the update mode it should be showed only if the user click the button.

我已经尝试了一些东西,我可以使用 Primefaces 引擎按 MB 调用对话框,如下所示:

I've already tried some things, I can call the dialog by MB using Primefaces engine as below:

 RequestContext.getCurrentInstance().execute("dialogArmaBos.show()")

这个命令非常适合按钮案例,但我可以在页面打开时让它工作.如果我尝试在 PostConstruct 中使用什么都不会发生.

This command Works great for the button case, but I can get it working when the page opens. If I try to use in the PostConstruct nothing happens.

我也尝试了 <f:event type="preRenderView" ...<f:metadata ... 但也没有任何变化.

I tried also <f:event type="preRenderView" ... with <f:metadata ... but nothing changes too.

有什么办法可以做到吗?

Is there some way to make it?

推荐答案

根据PrimeFaces 文档 有一个可见的属性.来自文档的引用:

According to the fabulous PrimeFaces documentation There is a visible attribute. Quote from the docs:

visible false Boolean 启用时,对话框默认可见.

visible false Boolean When enabled, dialog is visible by default.

因此只需在该属性中使用 EL 即可在页面加载时显示

So simply use an EL in that attribute to have it show on pageload

<p:dialog visible="#{myBean.createMode}"... >

并且在该 bean 中有一个布尔字段,如果处于创建模式则返回 true.

and have a boolean field in that bean that returns true if in creation mode.

其余的,如果需要,您可以使用客户端 api 显示/隐藏它

For the rest you can show/hide it with the client-side api if needed

这篇关于打开页面时如何打开对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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