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);
runScripts(scripts);
} 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);
}
}
}