public String getFunction(FacesContext context, UIAjaxFunction component) {
StringBuffer script = new StringBuffer(component.getName()).append("=");
JSFunctionDefinition func = new JSFunctionDefinition();
//func.setName(component.getName());
// Create AJAX Submit function.
JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(
component, context,AjaxRendererUtils.AJAX_FUNCTION_NAME);
Map options = AjaxRendererUtils.buildEventOptions(context, component);
Map parameters = (Map) options.get("parameters");
if (null == parameters) {
parameters = new HashMap();
options.put("parameters", parameters);
}
ajaxFunction.addParameter(JSReference.NULL);
ajaxFunction.addParameter(options);
// Fill parameters.
for (Iterator it = component.getChildren().iterator(); it.hasNext();) {
UIComponent child = (UIComponent) it.next();
if (child instanceof UIParameter) {
UIParameter parameter = ((UIParameter) child);
String name = parameter.getName();
func.addParameter(name);
// Put parameter name to AJAX.Submit parameter, with default value.
JSReference reference = new JSReference(name);
if (null != parameter.getValue()) {
reference = new JSReference(name + "||"
+ ScriptUtils.toScript(parameters.get(name)));
}
// Replace parameter value to reference.
parameters.put(name, reference);
}
}
func.addToBody(ajaxFunction.toScript());
func.appendScript(script);
return script.toString();
}