【问题标题】:Prevent p:dialog close using h:commandButton使用 h:commandButton 防止 p:dialog 关闭
【发布时间】:2014-02-27 03:12:23
【问题描述】:

我对 p:dialog 有疑问。我将它用作我的 JSF 2.2 应用程序的一部分:

<p:dialog id="cpaDialog" width="300px" widgetVar="changePasswordAdmin" header="#{msg['account.password.change']}" draggable="false" resizable="false">
    <h:form id="changePasswordAdminForm">
        <h:commandButton immediate="true" value="#{msg['cancel']}" onclick="PF('changePasswordAdmin').hide();"/>
        <p:commandButton id="submitCpa" update="changePasswordAdminForm" value="#{msg['submit']}" action="#{accountEditBean.changeAdminPassword()}" oncomplete="if (args &amp;&amp; !args.validationFailed) changePasswordAdmin.hide()"/>

        <!-- THERE ARE REQUIRED FIELD -->

    </h:form>
</p:dialog>

目前我正在使用p:commandButton 提交我的表单并在验证成功通过时关闭对话框。问题是我想在那里使用h:commandButton。你可能会问为什么。案例很简单。我需要这个按钮看起来像一个标准的 h:commandButton 而不应用任何 Primefaces 样式类。

您可能会告诉我:“从 primefaces 按钮中删除所有样式类”。我知道这是可能的(但不是那么有效)如果可能的话,我更愿意在这里使用h:commandButton

我试过了:

<h:commandButton id="submitCpa" value="#{msg['submit']}" action="#{accountEditBean.changeAdminPassword()}" >
    <f:ajax onevent="if (args &amp;&amp; !args.validationFailed) changePasswordAdmin.hide()"/>
</h:commandButton>

我使用这个非primefaces按钮的问题是每次按下它都会关闭对话框,而不取决于验证是否成功。

有谁知道在这种特殊情况下如何使用h:commandButton

【问题讨论】:

    标签: jsf jsf-2 primefaces dialog


    【解决方案1】:

    问题是由于未捕获的引用错误:未定义参数。该错误导致对话框关闭。

    我的建议是,您可以使用以下方式将对话框关闭操作委托给托管 Bean:

    org.primefaces.context.RequestContext context = RequestContext.getCurrentInstance();
    context.execute("changePasswordAdmin.hide()");
    

    你的按钮可以这样渲染:

    <h:commandButton id="submitCpa" value="#{msg['submit']}"  >
        <f:ajax listener="#{accountEditBean.changeAdminPassword()}" execute="changePasswordAdminForm" render="changePasswordAdminForm" />
    </h:commandButton>
    

    【讨论】:

    • 谢谢,它成功了! :)
    猜你喜欢
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多