private void _renderPartialScripts(
FacesContext context,
RenderingContext arc,
ScriptBufferingResponseWriter scriptBufferingWriter) throws IOException
{
PartialPageContext pprContext = arc.getPartialPageContext();
if (_shouldRenderPartialScripts(pprContext))
{
Iterator<String> targets = pprContext.getRenderedPartialTargets();
String scripts = scriptBufferingWriter.getBufferedScripts();
ResponseWriter writer = context.getResponseWriter();
// For XMLDOM, write out all the PPR scripts and the
// PPR targets as XML elements
if (supportsXMLDOM(arc))
{
writer.startElement("pprscripts", null);
if (scripts != null)
{
writer.write("<![CDATA[");
writer.writeText(scripts, null);
writer.write("]]>");
}
writer.endElement("pprscripts");
writer.startElement("pprtargets",null);
while (targets.hasNext())
{
String target = targets.next();
if (pprContext.isPartialTargetRendered(target))
{
writer.startElement("pprtarget", null);
writer.writeAttribute("targetid",target,null);
writer.endElement("pprtarget");
}
}
writer.endElement("pprtargets");
}
// Otherwise, write out the targets in a Javascript array,
// and add a Javascript load handler to load everything up
else
{
// Render the rest of the scripts if necessary
writer.startElement("script", null);
writer.writeAttribute("id", _PARTIAL_SCRIPTS_ID, null);
renderScriptTypeAttribute(context, arc);
// We comment out all of the script contents to avoid
// executing the scripts in the iframe. Our
// _partialChange() onload handler will explicitly execute
// the scripts in the parent window's context.
writer.writeText("/*", null);
// Render scripts
if (scripts != null)
writer.writeText(scripts, null);
// Close the comment
writer.writeText("*/", null);
writer.endElement("script");
Iterator<Object> libraries =
scriptBufferingWriter.getBufferedLibraries();
writer.startElement("script", null);
XhtmlRenderer.renderScriptTypeAttribute(context, arc);
writer.writeText("var ", null);
writer.writeText(_PARTIAL_PAGE_LIBRARIES_VAR, null);
writer.writeText("=[", null);
boolean firstRenderedLibrary = true;
if (libraries != null)
{
while (libraries.hasNext())
{
if (firstRenderedLibrary)
firstRenderedLibrary = false;
String libraryURI = libraries.next().toString();
writer.writeText("'", null);
writer.writeText(libraryURI, null);
writer.writeText("',", null);
}
}
// And include ScriptEval too.
writer.writeText("'", null);
writer.writeText(context.getExternalContext().getRequestContextPath(),
null);
writer.writeText(LibraryScriptlet.getBaseLibURL(), null);
String versionedLibraryName =
LibraryScriptlet.getLibraryNameWithVersion(context,
_SCRIPT_EVAL_LIBRARY_NAME);
writer.writeText(versionedLibraryName, null);
writer.writeText(".js'", null);
writer.writeText("];", null);
writer.writeText("var ", null);
writer.writeText(_PARTIAL_PAGE_TARGETS_VAR, null);
writer.writeText("=[", null);
// Loop through the partial targets and write out ids for any
// rendered targets.
boolean firstRenderedTarget = true;
while (targets.hasNext())
{
String target = targets.next();
if (pprContext.isPartialTargetRendered(target))
{
if (firstRenderedTarget)
firstRenderedTarget = false;
else
writer.writeText(",", null);