JSF Language switcher and ajax update

后端 未结 1 1142
清歌不尽
清歌不尽 2021-01-20 15:37

This question is a follow - up of the older Language switcher implementation in JSF 2.

The substance of the question is still valid, although PrimeFaces has released

相关标签:
1条回答
  • 2021-01-20 16:02

    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>
    
    0 讨论(0)
提交回复
热议问题