hide dialog, but do not fire ajax event

UI Components for JSF
Post Reply
javaone9
Posts: 317
Joined: 06 Nov 2012, 20:50

27 Jul 2014, 00:57

Code: Select all

    <p:dialog id="dialog1" widgetVar="dlg">
        <p:ajax event="close"  listener="#{dialogView.handleClose}" />
    </p:dialog>

   <h:outputLink value="javascript:void(0)" onclick="PF('dlg').hide();">Hide Dialog</h:outputLink>
When the dialog is hidden by hide() method, it will fire ajax event (close). Is there a way to control whether to fire the ajax event? like:

Code: Select all

PF('dlg').disableAjax();
PF('dlg').hide(false);
I am trying to close dialog from server side using javascript,

Code: Select all

"PF('dlg').hide();"
In this case, there is no need to fire ajax event to server. For example, open a dialog, fill out a form in dialog and submit, then close dialog automatically.

Thanks,
Dave

bsanders1979
Posts: 69
Joined: 02 Jun 2013, 18:37

27 Jul 2014, 04:42

Hello Dave,
This is simple. onstart="return false" will prevent the RT to the server. How is this useful you ask? You could actually do something like "return onStartCloseDialog()" and then in onStartCloseDialog(), write the logic to determine whether or not the AJAX event should fire.
PF 5.0
PF Ext 0.7.1
OmniFaces 1.7
Tomcat 7.0.37
JSF 2.1.24

javaone9
Posts: 317
Joined: 06 Nov 2012, 20:50

29 Jul 2014, 02:51

Thanks for reply. The dialog I am trying to close may not have the hookup(s) that you mentioned. It would be nice that the widget.hide() method has a parameter.

bsanders1979
Posts: 69
Joined: 02 Jun 2013, 18:37

29 Jul 2014, 05:50

onstart is a standard AJAX-related attribute. There's nothing stopping you from adding methods to either an entire widget class, or just a specific instance of one.

Code: Select all

    <p:dialog id="dialog1" widgetVar="dlg">
        <p:ajax event="close" onstart="return PF('dlg').onStartClose()" listener="#{dialogView.handleClose}" />
    </p:dialog>

   <h:outputLink value="javascript:void(0)" onclick="PF('dlg').setAjax(false); PF('dlg').hide();">Hide Dialog</h:outputLink>

<script type="text/javascript">
PF('dlg').setAjax = function(ajax) {
  this.ajax = ajax;
}

PF('dlg').isAjax = function() {
  return this.ajax;
}

PF('dlg').onStartClose = function() {
  try {
    return this.isAjax();
  }
  finally {
    this.setAjax(true);
  }
}
</script>
There are plenty of ways to achieve this, but this is based on your original post.
PF 5.0
PF Ext 0.7.1
OmniFaces 1.7
Tomcat 7.0.37
JSF 2.1.24

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 47 guests