StringBuilder builder = new StringBuilder();
Map<String, Object> eventOptions = AjaxRendererUtils.buildEventOptions(context, tree, true);
Map<String, Object> parameters = (Map<String, Object>) eventOptions.get("parameters");
parameters.remove(id);
parameters.put(id + UITree.SELECTED_NODE_PARAMETER_NAME, new JSReference("event.selectedNode"));
eventOptions.put("parameters", new JSReference("params"));
builder.append("var params = ").append(ScriptUtils.toScript(parameters)).append(";\n");
builder.append("if (!params.").append(AjaxRendererUtils.AJAX_SINGLE_PARAMETER_NAME)
.append(" && event.ajaxSingle) {\n");
builder.append("params.").append(AjaxRendererUtils.AJAX_SINGLE_PARAMETER_NAME).append(" = event.ajaxSingle;\n");
builder.append("}\n");
if (!eventOptions.containsKey("oncomplete")) {
eventOptions.put("oncomplete", new JSReference("event.oncomplete"));
}
JSFunction function = AjaxRendererUtils.buildAjaxFunction(tree, context);
function.addParameter(eventOptions);
builder.append(function);