【问题标题】:Primefaces: Growl message disappears immediately when closing the dialogPrimefaces:关闭对话框时咆哮消息立即消失
【发布时间】:2016-04-24 22:29:05
【问题描述】:

我正在使用 JSF2.2 Majorra 和 Primefaces 5.1 构建一个 Web 应用程序。

我有一个对话框,我需要验证,当有效时,执行操作。

在我调用的那个动作方法中,我可能会也可能不会发送一些 p:growl 消息。他们出现了,我看到了他们:

if (conflict >= 1) {
    try {
        if (!user.getId().equals(projektLeiter.getId())) {
            logger.info("CONFLICT.........................sending notification email to "
                    + projektLeiter.getFullName() + " with email " + projektLeiter.getEmail());
            EMailUtil.sendMailForOverlap(projektLeiter, currentProject, absence);
            MessageUtil.showGrowlWarn("Eventkonflikt festgestellt!<br/><br/>Leiter des Projekts '"
                    + currentProject.getNameShort() + "' wurde informiert.");
            RequestContext.getCurrentInstance().update("btnForm:growl");
        } else {
            MessageUtil.showGrowlWarn(
                    "Eventkonflikt mit Projekt '" + currentProject.getNameShort() + "' festgestellt!");
        }
    } catch (MessagingException e) {
        logger.catching(e);
        MessageUtil.showGrowlError(
                "Fehler: Kann keine Emails verschicken! Bitte informieren Sie den Administrator.");
    }
}

但是,在提交按钮的 oncomplete 中,我告诉对话框在验证没有失败时消失,如下所示:

<p:commandButton value="Speichern" process="detailsBookingDlg"
    update=":dialogForm:detailsBookingInner :dataTableForm:absenceTable"
    action="#{absenceController.onSaveButtonClick}"
    oncomplete="if (!args.validationFailed) {PF('detailsBookingWdgt').hide()}" />

我使用网络包资源管理器来查找问题。有一个额外的 POST 用于关闭对话框:

http://s21.postimg.org/6f0nylbs7/close.png

这个帖子让我的消息消失了。所以这就是问题所在。当我取出 oncomplete 时,它​​们会留下来。

在显示消息之前,我尝试使用 RequestContext 从操作方法中关闭对话框,但由于 close-POST 似乎总是最后一个,所以这没有奏效。

我使用的模板涉及到一个 navigation.xhtml,其中包括 p:growl:

<h:form id="btnForm">
    <div id="welcomeMessage">
        <h:outputText value="#{sessionBean.welcome}" escape="false" />
    </div>
    <p:growl id="growl" showDetail="false" life="10000" autoUpdate="true" redisplay="true" globalOnly="true"
        escape="false" />
</h:form>

我摆弄了按钮和咆哮的属性,但是当我关闭对话框时,消息不断消失。 这个我好像搞不清楚。

有什么想法吗?

【问题讨论】:

  • 我在你的代码中看不到任何咆哮......请创建一个minimal reproducible example。您很可能在咆哮中有“自动更新”之类的东西?
  • 试过删除 autoUpdate="true" 吗?
  • 它不是唯一一个使用咆哮容器的页面,所以我很遗憾地将 autoUpdate 设置为 true
  • T R Y 。 . .请。如果它发挥作用,你有更多的信息.​​.....

标签: ajax jsf-2 primefaces


【解决方案1】:

我的一位同事找到了答案:

在有问题的对话框中,我有一个 p:ajax 事件:

 <p:ajax event="close" immediate="true" update=":mainForm:timeline"
                listener="#{absenceAdministrationController.onCancelButtonClick}" />

每次我隐藏对话框时都会调用它。此事件仅在单击右上角的小“x”时触发,我完全摆脱了这一点。

我在对话框中添加了一个“取消”按钮,并将其设置为 closable="false"。

这解决了我隐藏一些消息时遇到的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多