【问题标题】:How to close a p:dialog after a p:commandButton action?如何在 p:commandButton 操作后关闭 p:dialog?
【发布时间】:2014-07-15 21:57:49
【问题描述】:

我有一个p:dialog,在单击p:dataTable 行后显示。我在p:dialog 中有一个p:commandButton,它有一个像这样的action

<p:commandButton value="Cambiar" action="#{adminUsuarios.cambiarPerfil()}" update="tblUsuarios" />

方法cambiarPerfil()

public void cambiarPerfil() {
    // More stuff here
    this.listaUsuarios = null; // Clear the list
}

这很好,但我想在p:commandButton action 之后关闭p:dialog

这是对话框:

<h:form id="myForm">
    <!-- More stuff-->
    <p:dialog id="myDialog" widgetVar="editarDialog" header="Editar perfil de usuario #{adminUsuarios.usuarioSeleccionado.id_User}" resizable="false" width="400" showEffect="size" hideEffect="size">
        <p:commandButton value="Cambiar" action="#{adminUsuarios.cambiarPerfil()}" update="tblUsuarios" />
    </p:dialog>
</h:form>

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    您需要在commandButton 中添加一个oncomplete 客户端方法。

    <h:form id="myForm">
        ...
        <p:dialog id="myDialog" widgetVar="editarDialog" ...>
            <p:commandButton value="Cambiar" action="#{adminUsuarios.cambiarPerfil()}" update="tblUsuarios" oncomplete="editarDialog.hide();"/>
        </p:dialog>
    </h:form>
    

    如果您使用的是 PF5.0,您可能需要将其更改为 oncomplete="PF('editarDialog').hide();",其中 editarDialog 是您对话框的 widgetVar

    【讨论】:

    • 我也是这样做的:RequestContext context = RequestContext.getCurrentInstance(); context.execute("editarDialog.hide();");cambiarPerfil() 方法中。
    • @KazMiller 我也是*(*我的评论抄袭了电影《肖桑克的救赎》)
    • 使用:oncomplete="PF('editarDialog').hide();" PF 5.0 或更高
    猜你喜欢
    • 2013-09-28
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    相关资源
    最近更新 更多