JSF Language switcher and ajax update

心已入冬 提交于 2019-12-01 20:16:37

The update="@all" of all PrimeFaces versions until now (3.4.2) is known to fail in IE. Any JavaScript code delivered along with the ajax response isn't been initialized properly.

This is discussed in this PrimeFaces forum topic and reported as issue 4731.

Until they fix it, your best bet is to workaround it by loading the following piece of JavaScript on every view which (possibly) contains an update="@all" command:

var originalPrimeFacesAjaxResponseFunction = PrimeFaces.ajax.AjaxResponse;
PrimeFaces.ajax.AjaxResponse = function(responseXML) {
   var newViewRoot = $(responseXML.documentElement).find("update[id='javax.faces.ViewRoot']").text();

    if (newViewRoot) {
       $('head').html(newViewRoot.substring(newViewRoot.indexOf("<head>") + 6, newViewRoot.indexOf("</head>")));
       $('body').html(newViewRoot.substring(newViewRoot.indexOf("<body>") + 6, newViewRoot.indexOf("</body>")));
    } else {
        originalPrimeFacesAjaxResponseFunction.apply(this, arguments);
    }
};

Provide this in flavor of a JS file which is loaded by <h:outputScript target="head"> inside the <h:body> in order to enforce the right loading order.

<h:body>
    <h:outputScript name="script.js" target="head" />
    ...
</h:body>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!