Primefaces:关闭对话框时咆哮消息立即消失

Primefaces: Growl message disappears immediately when closing the dialog

我正在使用 JSF2.2 Majorra 和 Primefaces 5.1 构建 Webapp。

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

在我调用的那个操作方法中,我可能会也可能不会发送一些 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.");
    }
}

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

<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

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

我尝试在显示消息之前使用 RequestContext 从操作方法中关闭对话框,但是由于关闭-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>

我摆弄了按钮和咆哮的属性,但是当我关闭对话框时,消息不断消失。 我似乎无法弄清楚这一点。

有什么想法吗?

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

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

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

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

我在对话框中添加了一个 'Cancel' 按钮并使其可关闭="false"。

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