2

I was trying something like below --

<h:commandButton id="btnOK">
     <f:ajax event="action" execute="@this" render="idHeader"       
listener="#{myBean.actionSubmit()}"/>
</h:commandButton>

And I want when that ajax request completes, do some processing in the UI.I am using following jQuery code for that :

$(document).ajaxComplete(function() {
    $.modal.close();
});

But my problem is the jQuery method is not fired at all. I am wondering if JSF ajax submission fires the ajaxComplete event or not??

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1220373
  • 383
  • 1
  • 9
  • 19
  • I have had some issues with this "success" state in my onevent javascript function. It seems that every browser other than IE has no issue, and re-renders the component after it returns a success state. IE though re-renders AFTER the success state is returned. This is definitely a problem if you're trying to manipulate something in the re-rendered component from your javascript. Every other browser works great though...I have yet to see a work-around for this IE issue. – james Aug 03 '12 at 12:15

2 Answers2

4

The standard JSF impl doesn't use jQuery API to send ajax requests. JSF uses its own internal API which you can find in the auto-included jsf.js file. So the jQuery jQuery.ajaxComplete() is never called. It would only be called when jQuery's $.ajax() (and its shortcuts $.get(), $.post(), etc) is being used. Only jQuery based component libraries use them such as PrimeFaces with <p:commandXxx> and <p:ajax>. For standard JSF <f:ajax>, you need to use JSF's own jsf.ajax.addOnEvent() handler instead, or the onevent attribute of the <f:ajax>.

In your particular case I think the onevent attribute is mose easy:

<f:ajax ... onevent="btnOKhandler" />

with

function btnOKhandler(data) {
    if (data.status == 'success') {
        $.modal.close();
    }
}

The data.status can have 3 values: begin, complete and success. See also tables 14-4 and 14-3 of the JSF specification.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

This is works for me instead $(document).ajaxComplete();

RichFaces.jQuery(document).on( 'ajaxcomplete', function(event, xhr, settings){   
     console.log(event, xhr, settings);
      // event, undefined, undefined
})
Alexufo
  • 1,723
  • 1
  • 15
  • 30