JSF 2.0利用JS函数处理Ajax异常

    JSF2.0规范中定义Ajax异常信息的形式为:

    
        ...
        ...
    
    可参见com.sun.faces.context.AjaxExceptionHandlerImpl的源码。
    JSF提供了全局脚本函数addOnError()用于监控Ajax错误,将函数定义在全局模板内可以实现页面共用。
    全局函数定义在jsf.ajax.js文件中,使用全局函数的页面应引用该脚本资源文件:

   
    定义全局回调函数:

  
    var handleError = function(data){
      var componentId = data.source.id;
      var xml = data.responseXML;
      var text = data.responseText;
      var code = data.responseCode;
      var type = data.type;
      var status = data.status;
      var description = data.description;
      var errorName = data.errorName;
      var errorMessage = data.errorMessage;

      var error = ... + ... + ....;
      alert(error);
      location.href = "/welcome.xhtml";
    };
    jsf.ajax.addOnError(handleError);
  
 

你可能感兴趣的:(JSF)