*/
public void encodeEnd(FacesContext context, UIComponent component)
throws IOException {
super.encodeEnd(context, component);
XForm comp = (XForm)component;
ChibaBean chiba = comp.chiba();
if (logger.isDebugEnabled()) {
try {
logger.debug ("Chiba document:\n" + XMLUtil.w3cDomToString
(chiba.getXMLContainer().getDocumentElement()));
} catch (XFormsException e) {
logger.debug (e.getMessage());
}
}
Object response = context.getExternalContext().getResponse();
if (response instanceof RenderResponse) {
try {
Element form = chiba.getXMLContainer().getDocumentElement();
NodeList titles
= form.getElementsByTagNameNS(XMLUtil.XMLNS_XHTML, "title");
if (titles.getLength() > 0) {
String title = XMLUtil
.getFirstLevelTextContent((Element)titles.item(0));
((RenderResponse)response).setTitle(title);
}
} catch (XFormsException e) {
logger.debug (e.getMessage());
}
}
// Ensure availability of JS
JSLoading.ensureInclusion(context, JSLoading.UTIL);
JSLoading.ensureInclusion(context, JSLoading.ANCHOR_POSITION);
JSLoading.ensureInclusion(context, JSLoading.DATE);
JSLoading.ensureInclusion(context, JSLoading.POPUP_WINDOW);
JSLoading.ensureInclusion(context, JSLoading.CALENDAR_POPUP);
AddResource addResource = AddResourceFactory.getInstance(context);
if (!context.getExternalContext().getRequestMap()
.containsKey(XFormRenderer.class.getName() + "_SCRIPTS")) {
addResource.addJavaScriptAtPosition
(context, AddResource.HEADER_BEGIN,
new MyFacesResourceHandler(XFormRenderer.class, "helpers.js"));
addResource.addJavaScriptAtPosition
(context, AddResource.HEADER_BEGIN,
new MyFacesResourceHandler
(XFormRenderer.class, "xforms2html.js"));
context.getExternalContext().getRequestMap()
.put(XFormRenderer.class.getName() + "_SCRIPTS", Boolean.TRUE);
}
// Add styles
addResource.addStyleSheet
(context, AddResource.HEADER_BEGIN,
new MyFacesResourceHandler(XFormRenderer.class, "xforms.css"));
// Write individual JS
ResponseWriter writer = context.getResponseWriter();
writer.startElement(HTML.SCRIPT_ELEM, null);
writer.writeAttribute
(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
String jsPrefix = JavascriptUtils
.getValidJavascriptName(comp.getClientId(context),false);
writer.write("window." + jsPrefix + "baseData={\n");
writer.write("jsPrefix: \"" + jsPrefix + "\",\n");
writer.write("elementIdPrefix: \""
+ comp.getClientId(context)
+ NamingContainer.SEPARATOR_CHAR + "\",\n");
String urlPrefix = addResource.getResourceUri
(context, new MyFacesResourceHandler(JSLoading.class, ""));
writer.write("resourcePrefix: \"" + urlPrefix + "\",\n");
writer.write("dataPrefix: \"" + DATA_PREFIX + "\",\n");
writer.write("triggerPrefix: \"" + TRIGGER_PREFIX + "\",\n");
writer.write("removeUploadPrefix: \"" + REMOVE_UPLOAD_PREFIX + "\",\n");
Locale locale = context.getViewRoot().getLocale();
ResourceBundle l10n = ResourceBundle.getBundle
("de.danet.an.util.jsf.xftaglib.L10n",
locale, XFormRenderer.class.getClassLoader());
writer.write("dateFormat: \"" + l10n.getString("dateFormat") + "\",\n");
writer.write
("dateTimeFormat: \"" + l10n.getString("dateTimeFormat") + "\",\n");
writer.write("monthsNames: new Array("
+ join(monthsNames(locale), "\"", ",") + "),\n");
writer.write("abbrevMonthsNames: new Array("
+ join(abbrevMonthsNames(locale), "\"", ",") + "),\n");
writer.write("todayLabel: \"" + l10n.getString("todayLabel") + "\",\n");
String path
= MyFacesAjaxServlet.getAjaxActionUrl(context, component);
if (path.indexOf("?") < 0) {
path = path + "?";
} else {
path = path + "&";
}
writer.write("ajaxBaseUrl: \"" + path + "\"\n");
writer.write("};\n");
String guiData = null;
try {
Transformer t;
t = defTemplates().newTransformer();
StringWriter sw = new StringWriter();
t.transform(new DOMSource(chiba.getXMLContainer()),
new StreamResult(sw));
guiData = sw.toString();
} catch (TransformerConfigurationException e) {
logger.error (e.getMessage(), e);
} catch (TransformerFactoryConfigurationError e) {