in impl/src/main/java/org/apache/myfaces/renderkit/html/util/AjaxScriptBuilder.java [125:272]
public static void build(FacesContext context,
StringBuilder sb,
UIComponent component,
String sourceId,
String eventName,
String execute,
String render,
String delay,
String resetValues,
String onerror,
String onevent,
Collection<ClientBehaviorContext.Parameter> params,
List<UIParameter> uiParams,
String userParameters)
{
// CHECKSTYLE:ON
HtmlCommandScript commandScript = (component instanceof HtmlCommandScript hcs)
? hcs
: null;
sb.append(MYFACES_AB);
sb.append('(');
if (sourceId == null)
{
sb.append(AJAX_VAL_THIS);
}
else
{
sb.append('\'');
sb.append(sourceId);
sb.append('\'');
if (!sourceId.trim().equals(component.getClientId(context)))
{
// Check if sourceId is not a clientId and there is no execute set
UIComponent ref = (component.getParent() == null) ? component : component.getParent();
UIComponent instance = null;
try
{
instance = ref.findComponent(sourceId);
}
catch (IllegalArgumentException e)
{
// No Op
}
if (instance == null && execute == null)
{
// set the clientId of the component so the behavior can be decoded later,
// otherwise the behavior will fail
execute = component.getClientId(context);
}
}
}
sb.append(',');
sb.append(commandScript == null ? AJAX_VAL_EVENT : AJAX_VAL_NULL);
sb.append(",'");
sb.append(eventName);
sb.append("',");
SearchExpressionHandler seHandler = null;
SearchExpressionContext seContext = null;
if (StringUtils.isNotBlank(execute) || StringUtils.isNotBlank(render))
{
seHandler = context.getApplication().getSearchExpressionHandler();
seContext = SearchExpressionContext.createSearchExpressionContext(
context, component,
MyFacesSearchExpressionHints.SET_RESOLVE_CLIENT_SIDE_RESOLVE_SINGLE_COMPONENT, null);
}
appendIds(sb, execute, seHandler, seContext);
sb.append(',');
appendIds(sb, render, seHandler, seContext);
if (onevent != null || onerror != null || delay != null || resetValues != null
|| (params != null && !params.isEmpty()) || (uiParams != null && !uiParams.isEmpty()))
{
sb.append(",{");
if (onevent != null)
{
appendProperty(sb, AJAX_KEY_ONEVENT, onevent, false);
}
if (onerror != null)
{
appendProperty(sb, AJAX_KEY_ONERROR, onerror, false);
}
if (delay != null)
{
appendProperty(sb, AJAX_KEY_DELAY, delay, true);
}
if (resetValues != null)
{
appendProperty(sb, AJAX_KEY_RESETVALUES, resetValues, false);
}
if ((params != null && !params.isEmpty()) || (uiParams != null && !uiParams.isEmpty()))
{
StringBuilder paramsBuilder = SharedStringBuilder.get(context, AJAX_PARAM_SB, 60);
paramsBuilder.append('{');
if (params != null && !params.isEmpty())
{
if (params instanceof RandomAccess)
{
List<ClientBehaviorContext.Parameter> list = (List<ClientBehaviorContext.Parameter>) params;
for (int i = 0, size = list.size(); i < size; i++)
{
ClientBehaviorContext.Parameter param = list.get(i);
appendProperty(paramsBuilder, param.getName(), param.getValue(), true);
}
}
else
{
for (ClientBehaviorContext.Parameter param : params)
{
appendProperty(paramsBuilder, param.getName(), param.getValue(), true);
}
}
}
if (uiParams != null && !uiParams.isEmpty())
{
for (int i = 0, size = uiParams.size(); i < size; i++)
{
UIParameter param = uiParams.get(i);
appendProperty(paramsBuilder, param.getName(), param.getValue(), true);
}
}
paramsBuilder.append('}');
appendProperty(sb, AJAX_KEY_PARAMS, paramsBuilder, false);
}
sb.append('}');
}
else
{
sb.append(",{}");
}
if(userParameters != null && !userParameters.isEmpty())
{
sb.append(',');
sb.append(userParameters);
}
sb.append(')');
}