update="@all" not updating browser DOM

UI Components for JSF
Posts: 36
Joined: 23 Jul 2010, 20:21

18 May 2012, 20:47

I think I see the root cause. IE6/7/8 unfortunately doesn't run the embedded scripts when document.write() is been used to replace the DOM (I do however wonder what kind of an error page it is that it would require some JS/ajax code).

I'd suggest PrimeFaces to follow the same logic as the standard jsf.js is using to handle an update on javax.faces.ViewRoot. Here's an extract of relevance:

Code: Select all

            if (id === "javax.faces.ViewRoot" || id === "javax.faces.ViewBody") {
                var bodyStartEx = new RegExp("< *body[^>]*>", "gi");
                var bodyEndEx = new RegExp("< */ *body[^>]*>", "gi");
                var newsrc;

                var docBody = document.getElementsByTagName("body")[0];
                var bodyStart = bodyStartEx.exec(src);

                if (bodyStart !== null) { // replace body tag
                    // First, try with XML manipulation
                    try {
                        // Get scripts from text
                        scripts = stripScripts(src);
                        // Remove scripts from text
                        newsrc = src.replace(/<script[^>]*>([\S\s]*?)<\/script>/igm, "");
                        elementReplace(getBodyElement(newsrc), docBody);
                    } catch (e) {
                        // OK, replacing the body didn't work with XML - fall back to quirks mode insert
                        var srcBody, bodyEnd;
                        // if src contains </body>
                        bodyEnd = bodyEndEx.exec(src);
                        if (bodyEnd !== null) {
                            srcBody = src.substring(bodyStartEx.lastIndex, bodyEnd.index);
                        } else { // can't find the </body> tag, punt
                            srcBody = src.substring(bodyStartEx.lastIndex);
                        // replace body contents with innerHTML - note, script handling happens within function
                        elementReplaceStr(docBody, "body", srcBody);

Posts: 14
Joined: 18 May 2012, 11:37

21 May 2012, 09:37

Thanks for the reply BalusC!!
I see what you mean..
Well the error page itself doesn't uses JS/ajax (well that's not entirely true as it uses a Primefaces fieldset to collapse the printstack) but it uses a template that has some Primefaces components ( a menubar and a SelectOneMenu).

All of these components don't work after the replace of DOM.
I find it very strange though that the omnifaces FullAjaxExceptionHandler showcase works perfectly in ie8 as it uses primefaces panels in its error page template.

So is there any workaround to this problem or i must wait for primefaces to change their primefaces.js (if they decide to, of course).

Thanks again!
Primefaces 3.4
Mojarra 2.1.11
Shiro 1.2
Omnifaces 1.1
PF Extensions 0.5

Posts: 36
Joined: 23 Jul 2010, 20:21

04 Oct 2012, 17:34

It's because the ajax request was been handled by standard JSF <f:ajax> instead of PrimeFaces <p:commandXxx>.

Posts: 36
Joined: 23 Jul 2010, 20:21

04 Oct 2012, 17:59

I found a simpler way to fix this for now, using PrimeFaces-bundled jQuery. Execute this during onload:

Code: Select all

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);
This way jQuery will execute any JS/CSS contained in the new view, also in IE.
Last edited by BalusC on 04 Oct 2012, 18:17, edited 1 time in total.

Posts: 18465
Joined: 05 Jan 2009, 00:21
Location: Cybertron

04 Oct 2012, 18:10

Great, thanks Bauke. Noted down for 3.4.2;

http://code.google.com/p/primefaces/iss ... il?id=4731

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 20 guests