// Otherwise,
else {
// Ask the children to encode themselves and capture the markup in a string.
ResponseWriter backupResponseWriter = facesContext.getResponseWriter();
BufferedScriptResponseWriter bufferedScriptResponseWriter = new BufferedScriptResponseWriter();
facesContext.setResponseWriter(bufferedScriptResponseWriter);
super.encodeChildren(facesContext, uiComponent);
facesContext.setResponseWriter(backupResponseWriter);
// If running in an Ajax request, then it is not possible to render the scripts at the bottom of the
// portal page. Instead, store the script in the JavaScript map so that PartialViewContextCleanupImpl
// knows to include it in the <eval>...</eval> section of the JSF partial-response.
if (isAjaxRequest(facesContext)) {
Map<String, String> javaScriptMap = ExtFacesContext.getInstance().getJavaScriptMap();
javaScriptMap.put(uiComponent.getClientId(facesContext), bufferedScriptResponseWriter.toString());
}
// Otherwise, render the script at the bottom of the portal page by setting the WebKeys.AUI_SCRIPT_DATA
// request attribute.
else {
Map<String, Object> attributes = uiComponent.getAttributes();
String use = (String) attributes.get(USE);
String bufferedScript = bufferedScriptResponseWriter.toString();
RendererUtil.renderScript(facesContext, uiComponent, bufferedScript, use);
}
}
}