}
public JSONObject getAjaxParams(FacesContext context, OUICommand command) {
try {
JSONObject result = new JSONObject();
Iterable<String> execute = command.getExecute();
boolean submitAjaxInvoker =
command instanceof ComponentConfigurator || // e.g. when using Ajax in table selection, submit table params automatically
(command instanceof Ajax &&
!((Ajax) command).isStandalone()
&& ((Ajax) command).getSubmitInvoker());
if (execute.iterator().hasNext() || submitAjaxInvoker) {
result.put("execute", getExecuteParam(context, command, execute));
}
result.put("executeRenderedComponents", command.getExecuteRenderedComponents());
String onajaxstart = command.getOnajaxstart();
if (onajaxstart != null && onajaxstart.length() != 0) {
result.put("onajaxstart", new AnonymousFunction(onajaxstart, "event"));
}
String onajaxend = command.getOnajaxend();
if (onajaxend != null && onajaxend.length() != 0) {
result.put("onajaxend", new AnonymousFunction(onajaxend, "event"));
}
String onerror = command.getOnerror();
if (onerror != null && onerror.length() != 0) {
result.put("onerror", new AnonymousFunction(onerror, "event"));
}
String onsuccess = command.getOnerror();
if (onsuccess != null && onsuccess.length() != 0) {
result.put("onsuccess", new AnonymousFunction(onsuccess, "event"));
}
Integer delayObj = (Integer) command.getAttributes().get("delay");
int delay = delayObj != null ? delayObj : 0;
if (delay > 0) {
result.put("delay", delay);
result.put("delayId", getAjaxComponentParam(context, command));
}
MethodExpression action = !(command instanceof Ajax) ? command.getActionExpression() : null;
if (action != null) {
String actionExpressionString = action.getExpressionString();
validateExpressionString(actionExpressionString);
result.put("_action", actionExpressionString.substring(
EXPRESSION_PREFIX.length(), actionExpressionString.length() - EXPRESSION_SUFFIX.length()));
result.put("actionComponent", command.getClientId(context));
}
ValueExpression actionListener = command instanceof Ajax
? command.getValueExpression("listener")
: command.getValueExpression("actionListener");
if (actionListener != null) {
String actionListenerExpressionString = actionListener.getExpressionString();
validateExpressionString(actionListenerExpressionString);
result.put("listener", actionListenerExpressionString.substring(EXPRESSION_PREFIX.length(),
actionListenerExpressionString.length() - EXPRESSION_SUFFIX.length()));
result.put("actionComponent", getAjaxComponentParam(context, command));
}
result.put("immediate", command.isImmediate());
return result;
} catch (JSONException e) {
throw new RuntimeException(e);
}
}