【问题标题】:p:ajaxStatus how to show notification message after saving recordp:ajaxStatus 如何在保存记录后显示通知消息
【发布时间】:2016-10-21 15:27:47
【问题描述】:

我有一个保存按钮,它调用我的支持 Bean 中的一个方法。单击它时,我想显示通知消息,为此我选择了 Primefaces 的 ajaxStatus。 .这是按钮的代码(p:commandButton):

<p:commandButton value="OK"
    action="#{myBean.saveRecord}" />

以及它之外的 ajaxStatus:

<p:ajaxStatus onstart="PF('statusDialog').show();"
            onsuccess="PF('statusDialog').hide();" />
        <p:dialog modal="true" widgetVar="statusDialog"
            header="Success operation" draggable="false"
            closable="false" resizable="false" style="text-align: center">
        </p:dialog>

感谢您的帮助

【问题讨论】:

  • 问题出在哪里?
  • 如何为所有 xhtml 页面创建通用通知消息以不使用咆哮和消息组件,我会使用与 statusAjax 相同的原理。
  • 使用包含并在每个页面中添加这个 AjaxStuts 你怎么看

标签: jsf primefaces jsf-2


【解决方案1】:

在最后添加你的 saveRecord 方法:

RequestContext.getCurrentInstance().execute("PF('statusDialog').show();");

【讨论】:

  • 但是通过这条指令ManagedBean控制xhtml!
  • 好的,所以你可以把它放在你的 xhtml p:commandButton => onComplete="PF('statusDialog').show();"
【解决方案2】:

一旦您的页面上有一个 ajaxStatus,您在 onstart 和 onsuccess 事件上放置的 javascript 就会被触发,而您现在已经这样做了,对吧?!

在这些脚本中,您可以直接使用 widgetVar,因为 PrimeFaces 在全局(窗口)范围内使用您告知的名称创建 javascript 变量:

onstart="statusDialog.show();" onsuccess="statusDialog.hide();"

如果您想在其他页面上重复使用此解决方案,只需将其放在模板文件中即可:)

对不起,如果我误解了您的问题。

干杯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-11
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    • 2018-01-21
    相关资源
    最近更新 更多