title: Primefaces Growl onclose event?
body: <p>Is there any way to detect when the growl dialog has been closed, and act on that event?</p>
  
  <p>No ajax events are listed for growl in the PrimeFaces userguide, nor are there any onclose or oncomplete javascript handler attributes.</p>
  
  <p>The reason I need this, is that i use a poller which is deactivated when a dialog is opened, and i wish to reactivate the poller after the growl message is closed. </p>
  
  <p>I was reactivating the poller after the original dialog was closed, but for some reason the addition of the growl broke the reactivation of the poller. The restarted poller polled once till the growl appeared, then stopped. </p>
  
  <p>So .. my idea is to move the reactivation of the poller till after the growl is closed.</p>
  
  <p>The code is in several fragments, one fragment has the poller, which can be started and stopped via a toolbar button (only the poller shown here):</p>
  
  <pre><code>  &lt;h:form id="form-toolbar"&gt;
  
          &lt;!-- poller --&gt;
          &lt;p:poll id="pollerDataTable"
             widgetVar="p4mPollerDataTable"
             interval="10"
             async="true"
             global="false"
             update=":form-toolbar:dtItems"
             listener="#{controller.refreshDataTable}"
             autoStart="false" /&gt;
  
          [snip]
  
     &lt;/h:form&gt;
  </code></pre>
  
  <p>One fragment has the growls:</p>
  
  <pre><code>   &lt;h:form id="form-body-growl"&gt;
         &lt;p:growl id="growlSuccess" for="success" severity="info" infoIcon="/img/LOGO_H150.png"
                  warnIcon="/img/LOGO_H150.png" errorIcon="/img/LOGO_H150.png"
                  sticky="false" life="3000"/&gt;
         &lt;p:growl id="growlError" severity="warn, error" infoIcon="/img/LOGO_H150.png"
                  warnIcon="/img/LOGO_H150.png" errorIcon="/img/LOGO_H150.png"
                  sticky="true" globalOnly="true"/&gt;
     &lt;/h:form&gt;
  </code></pre>
  
  <p>One fragment has a command button to show the dialog:</p>
  
  <pre><code>    &lt;p:commandButton id="tbBtnNew"
                       icon="ui-icon-plus"
                       title="#{facesUtilsBean.getLocalizedText(webUiConstBean.BUNDLE_BASE_NAME_UI_STRING, 'toolbar.tooltip.new')}"
                       actionListener="#{controller.onShowNewDialog}"
                       update=":form-dlgNew:new"
                       onsuccess="p4mDlgNew.show();"/&gt;
      &lt;p:tooltip for="tbBtnNew" showEffect="fade" hideEffect="fade" /&gt;
  </code></pre>
  
  <p>Another contains the dialog being opened:</p>
  
  <pre><code>    &lt;!-- new dialog --&gt;
      &lt;h:form id="form-dlgNew"&gt;
          &lt;p:dialog header="New" id="dlgNew"
                    widgetVar="p4mDlgNew" resizable="false" dynamic="true" modal="true" closable="false"&gt;
  
              &lt;div class="dialog-container"&gt;
                  &lt;h:panelGrid id="new" columns="3" columnClasses="formText, formValue, formValidation" styleClass="defaultTable" style="width:100%;" rendered="#{not empty controller.editingItem}"&gt;
                      &lt;ui:insert name="newDialogColumns"/&gt;
                      &lt;p:spacer/&gt;
                      &lt;p:column colspan="2"&gt;
                          &lt;p:commandButton styleClass="cmdButtonSaveCancel" ajax="false"
                                           value="#{facesUtilsBean.getLocalizedText(webUiConstBean.BUNDLE_BASE_NAME_UI_STRING, 'dialog.save.button')}"
                                           actionListener="#{controller.onSaveNewDialog}" update=":form-toolbar:dtItems, :form-body-growl:growlSuccess, :form-body-growl:growlError"
                                           onsuccess="p4mDlgNew.hide();" process="new"/&gt;
                          &lt;p:commandButton styleClass="cmdButtonSaveCancel" ajax="false"
                                           value="#{facesUtilsBean.getLocalizedText(webUiConstBean.BUNDLE_BASE_NAME_UI_STRING, 'dialog.cancel.button')}"
                                           actionListener="#{controller.onCancelNewDialog}" update=":form-toolbar:dtItems" onsuccess="p4mDlgNew.hide();" process="@this"/&gt;
                      &lt;/p:column&gt;
                  &lt;/h:panelGrid&gt;
              &lt;/div&gt;
          &lt;/p:dialog&gt;
      &lt;/h:form&gt;
  </code></pre>
  
  <p>And then in the backing bean there are event handlers which pause and resume polling</p>
  
  <pre><code>public void suspendPolling() {
      RequestContext requestContext = RequestContext.getCurrentInstance();
      requestContext.execute(POLLER_DATATABLE_CLIENT_ID + ".stop();");
  }
  
  
  public void resumePolling() {
      RequestContext requestContext = RequestContext.getCurrentInstance();
      requestContext.execute(POLLER_DATATABLE_CLIENT_ID + ".start();");
  }
  
  
  public void onShowNewDialog(ActionEvent event) {
      if (isAutoRefreshActive()) {
          suspendPolling();
      }
  
      [snip]
  }
  
  
  /**
   * Called by new button template when 'cancel' button clicked.
   * Refreshes data and resumes polling if necessary.
   */
  public void onCancelNewDialog(ActionEvent event) {
  
      [snip]
  
      if (isAutoRefreshActive()) {
          resumePolling();
      }
  }
  
  
  /**
   * Called by new button template when 'accept' button clicked.
   * Refreshes data and resumes polling if necessary.
   */
  public void onSaveNewDialog(ActionEvent event) throws PSoftIOException {
  
      [snip]
  
      if (isAutoRefreshActive()) {
          resumePolling();
      }
  
  }
  </code></pre>
  
  <p>So, please, would there be a way to move the resumePolling functionality till after the growls are closed?</p>
  
  <p>Or .. alternatively (and better even), a way to fix the orginial problem, that the growls broke the poller?</p>
  
  <p>Cheers</p>
  
  <p>[edit ]</p>
  
  <p>Further Information regarding the active status of the poller.</p>
  
  <p>We check and controll the active status of the poller using the following code in the Bean:</p>
  
  <pre><code>private ToolBarRefreshController getToolBarRefreshController() {
      return (ToolBarRefreshController) FacesUtils.resolveBean("toolBarRefreshController");
  }
  
  private boolean isAutoRefreshActive() {
      ToolBarRefreshController toolBarRefreshController = getToolBarRefreshController();
      if (toolBarRefreshController == null) {
          return false;
      }
  
      return toolBarRefreshController.isAutoRefreshActive();
  }
  
  public void startAutoRefresh() {
      // nesting starting polling must be prevented
      if (!isAutoRefreshActive()) {
          refreshDataTable();
          resumePolling();
          getToolBarRefreshController().setAutoRefreshActive(true);
      }
  }
  
  
  public void stopAutoRefresh() {
      // nesting stopping polling must be prevented
      if (isAutoRefreshActive()) {
          suspendPolling();
          getToolBarRefreshController().setAutoRefreshActive(false);
      }
  }
  </code></pre>