Wednesday

Handling AJAX call error on client side

Just put the below code snippet to a JS file as below. (I used  immediately invoked functional expressions)

It is an error listener, it is called when JSF ajax request/response cyle gets an error.
(function jsfAjaxErrorHandler() {
 jsf.ajax.addOnError(function(data) {
   var log = "status:" +  data.status;
   log += " <br> message:" + data.message;
   log += " <br> description:" + data.description;
   log += " <br> serverErrorName:" + data.serverErrorName;
   log += " <br> serverErrorMessage:" + data.serverErrorMessage;
   log += " <br> source:" + data.source;
   log += " <br> responseCode:" + data.responseCode;
   log += " <br> responseText:" + data.responseText;
   log += " <br> responseXML:" + data.responseXML;
   
   alert(log);
 });
})();

Then load your js file but your js file must be loaded after JSF's own 'jsf.js' file.
<h:outputScript library="javax.faces" name="jsf.js"/>
<h:outputScript name="/yours.js" library="js"/> 

No comments:

Post a Comment