throw new IllegalArgumentException(
"One of the necessary attributes is null or empty. Check operation attribute and selector or target attributes.");
}
JSFunctionDefinition callback = new JSFunctionDefinition();
callback.addParameter(new JSReference(REF_EVENT));
callback.addParameter(new JSReference(REF_COMPONENT));
// create callback function
StringBuffer script = new StringBuffer();
script.append(REF_COMPONENT).append("['").append(apiFunctionName).append("'].").append("apply").append("(");
// get client api function parameters
List<Object> apiFunctionParams = createSignature(controlBehavior);
script.append(REF_COMPONENT).append(",").append(ScriptUtils.toScript(apiFunctionParams.toArray())).append(");");
callback.addToBody(script);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(PARAM_CALLBACK, callback);
parameters.put(PARAM_TARGET, resolveTargets(facesContext, targetSourceString));
parameters.put(PARAM_SELECTOR, selector);
String onBeforeOperation = controlBehavior.getOnbeforeoperation();
if (null != onBeforeOperation && !onBeforeOperation.isEmpty()) {
JSFunctionDefinition onBeforeOperationFunction = new JSFunctionDefinition(new JSReference(REF_EVENT));
onBeforeOperationFunction.addToBody(onBeforeOperation);
parameters.put(PARAM_ONBEFOREOPERATION, onBeforeOperationFunction);
}
// execution function
JSFunction eventFunction = new JSFunction(FUNC_NAME);
eventFunction.addParameter(new JSReference(REF_EVENT));
eventFunction.addParameter(parameters);
StringBuffer execution = new StringBuffer();
execution.append(eventFunction.toScript());
execution.append("; return false;");