Primefaces:所有ajax请求的默认oncomplete方法 [英] Primefaces: Default oncomplete method for all ajax request

查看:23
本文介绍了Primefaces:所有ajax请求的默认oncomplete方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为所有 ajax 请求配置一个 oncomplete 方法,以便我可以处理会话超时.

I am trying to configure an oncomplete method for all ajax requests so that I can handle session timeout.

我尝试添加以下脚本,但它的工作方式与为 p:ajax 元素设置 oncomplete 属性的方式不同.它不会在每次发出 Ajax 请求时执行.

I tried adding the following script but it didn't work the same way as setting oncomplete property for p:ajax element. It wouldn't execute each time an Ajax request is made.

$.ajaxSetup({method: post,
    complete: function(xhr, status, args){
        var xdoc = xhr.responseXML;
        if(xdoc == null){
            return;
        }
        errorNodes = xdoc.getElementsByTagName('error-name');

        if (errorNodes.length == 0) {
            return;
        }

        errorName = errorNodes[0].childNodes[0].nodeValue;
        errorValueNode = xmlDoc.getElementsByTagName('error-message');
        errorValue = errorValueNode[0].childNodes[0].nodeValue;

        alert(errorValue);
        document.location.href='${pageContext.request.contextPath}/login/login.jsf';
    }
});

任何帮助将不胜感激

推荐答案

我设法通过包装 Primefaces AjaxUtils 方法来实现这一点.

I managed to implement this by wrapping Primefaces AjaxUtils method.

var originalPrimeFacesAjaxUtilsSend = PrimeFaces.ajax.AjaxUtils.send;

   PrimeFaces.ajax.AjaxUtils.send = function(cfg) {
      if (!cfg.oncomplete) {
         // register default handler
         cfg.oncomplete = oncompleteDefaultHandler;
      }
      originalPrimeFacesAjaxUtilsSend.apply(this, arguments);
   };

这篇关于Primefaces:所有ajax请求的默认oncomplete方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆