Jsf 当元素发生部分更新时捕获事件

Jsf 当元素发生部分更新时捕获事件,jsf,primefaces,Jsf,Primefaces,我有一个输出面板,如下所示: <p:outputPanel id="panel1" > ... </p:outputPanel> <p:outputPanel autoUpdate="true"> <h:outputScript id="getPartialUpdateEvent"> getPartialUpdateEvent(); </h:outputScript> &

我有一个输出面板,如下所示:

<p:outputPanel id="panel1" >
...
</p:outputPanel>
<p:outputPanel autoUpdate="true">
        <h:outputScript id="getPartialUpdateEvent">
            getPartialUpdateEvent();
        </h:outputScript>
    </p:outputPanel>



function getPartialUpdateEvent(){
           var e = event || window.event;
           if(e!=null){
            var target = e.target || e.srcElement;
            if(target!=null && target.responseText!=null && target.responseText.indexOf('id="panel1"')>0){
                console.log("Partial Update on panel1");
            }
           }
         }

...
在某些事件页面发生后(如单击以下菜单项)将更新:

<p:menuitem value="Menu 1" update=":panel1" ... />
<p:menuitem value="Menu 2" update=":panel1" ... />
<p:menuitem value="Menu 3" update=":panel1" ... />
<p:menuitem value="Menu 4" update=":panel1" ... />
<p:menuitem value="Menu 5" update=":panel1" ... />

我想捕获panel1上发生的所有部分更新ajax事件,我目前正在使用BalusC的回答,如下所示:

<p:outputPanel id="panel1" >
...
</p:outputPanel>
<p:outputPanel autoUpdate="true">
        <h:outputScript id="getPartialUpdateEvent">
            getPartialUpdateEvent();
        </h:outputScript>
    </p:outputPanel>



function getPartialUpdateEvent(){
           var e = event || window.event;
           if(e!=null){
            var target = e.target || e.srcElement;
            if(target!=null && target.responseText!=null && target.responseText.indexOf('id="panel1"')>0){
                console.log("Partial Update on panel1");
            }
           }
         }

getPartialUpdateEvent();
函数getPartialUpdateEvent(){
var e=事件| | window.event;
如果(e!=null){
var target=e.target | | e.src元素;
如果(target!=null&&target.responseText!=null&&target.responseText.indexOf('id=“panel1”)>0){
console.log(“panel1上的部分更新”);
}
}
}
但这有一个问题。我无法在firefox中获取XMLHttpRequest或事件对象,因此上述javascript在firefox中不起作用

对于所有浏览器,是否有其他方法可以在panel1上捕获此部分更新?
提前谢谢

在我看来,一个非常好的“通用”解决方案是重写PrimeFaces javascript ajax函数。如果您签出(可能它一直在您身边),您可以看到,对于每个需要更新的元素,总是调用一个函数。如果您重写了它,并在调用原始函数后,执行您自己的“操作”。在本例中(我们使用real),页面上更改的元素将突出显示

var originalPrimeFacesAjaxUtilsUpdateElement = PrimeFaces.ajax.Utils.updateElement;
PrimeFaces.ajax.Utils.updateElement = function(id, content, xhr) {
    //call the original function first that does the basic updating
    originalPrimeFacesAjaxUtilsUpdateElement.apply(this, arguments);
    // Do your work here... 
    if (id.contains("panel1")) {
      $(PrimeFaces.escapeClientId(id)).effect("highlight", {}, 3000);
      //console.log(id);
    }
};

这在其他浏览器中适用吗?就我个人而言,我会尝试这样做:在那里检查panel1是否是需要更新的id之一,并“做你的事”是的kukeltje。。。上述解决方案适用于所有其他浏览器,但不适用于firefox,因为window.event在这种情况下是未定义的。我会查看你的链接,谢谢汉克斯!这很有效。。。id.contains(“panel1”)给出了一个错误,因此替换为id==“panel1”,但这是可行的。