打开< p:dialog>从bean通过RequestContext#execute() [英] Open <p:dialog> from bean by RequestContext#execute()

查看:133
本文介绍了打开< p:dialog>从bean通过RequestContext#execute()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个表单与一个面板网格和一个对话框:

I have this form with a panel grid and a dialog:

<h:form id="regiForm">
    <p:panelGrid>
        <p:row style="height:30%">           
            <p:column>
                <h:outputText/> 
            </p:column>     
            <p:column>
                <p:commandButton style="width:350px" type="submit" actionListener="#
                {regiBean.showDialog}" id="ajax" value="#{msg['regi_button']}" update="regiForm"   process="@this"/>
            </p:column>  
            <p:column>
            </p:column>  
        </p:row>  
    </p:panelGrid>
    <p:dialog id="dialog" header="#{msg['regi_dialog_header']}" widgetVar="myDialog"  position="center center" >  
        <h:outputText value="#{msg['regi_dialog']}" />  
    </p:dialog>
</h:form>

我想从动作监听器内部打开对话框:

I would like to open the dialog from inside the action listener:

public void showDialog() {
    RequestContext.getCurrentInstance().execute("dialog.show()");
    RequestContext.getCurrentInstance().execute("myDialog.show()");
}

但是,该对话框未显示。这是如何引起的,如何解决?

However, the dialog is not shown. How is this caused and how can I solve it?

我使用的是JSF 2.1和PrimeFaces 3.5。

I'm using JSF 2.1 and PrimeFaces 3.5.

推荐答案

使用命令的第一个语句

RequestContext.getCurrentInstance().execute("dialog.show()");

将无法正常工作,因为对话框指的是 p:dialog 组件的XHTML ID。这将导致一个JavaScript错误。这可能是第二个命令的原因

won't work because dialog refers to the XHTML ID of the p:dialog component. This will cause an javascript error. And that could be the reason why the second command

RequestContext.getCurrentInstance().execute("myDialog.show()");

不会执行。
此外,我将添加; 到每个Javascript命令的末尾(但这只是我的个人风格)

won't get executed. Also I would add ; to the end of each Javascript command (but this is just my personal style)

这篇关于打开&lt; p:dialog&gt;从bean通过RequestContext#execute()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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