in trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlUtils.java [659:728]
public static String getClientEventHandler(
FacesContext facesContext,
UIComponent component,
String eventName,
String secondaryEventName,
String userHandlerScript,
String eventHandlerScript
)
{
BehaviorsData data = null;
if (component instanceof ClientBehaviorHolder)
{
data = new BehaviorsData();
_getBehaviorScripts(facesContext, component, eventName, data);
if (secondaryEventName != null)
{
_getBehaviorScripts(facesContext, component, secondaryEventName, data);
}
}
boolean hasHandler = eventHandlerScript != null && eventHandlerScript.length() > 0;
boolean hasUserHandler = userHandlerScript != null && userHandlerScript.length() > 0;
String script = null;
boolean hasBehaviors = data != null && data.behaviorScripts != null &&
!data.behaviorScripts.isEmpty();
if (hasHandler && !hasBehaviors && !hasUserHandler)
{
script = eventHandlerScript;
}
else if (hasUserHandler && !hasBehaviors && !hasHandler)
{
script = userHandlerScript;
}
else if (!hasUserHandler && !hasHandler && hasBehaviors && data.behaviorScripts.size() == 1)
{
script = data.behaviorScripts.get(0);
}
else
{
// There are multiple scripts, we will need to chain the methods.
int numBehaviorScripts = hasBehaviors ? data.behaviorScripts.size() : 0;
int length = numBehaviorScripts;
if (hasHandler) { ++length; }
if (hasUserHandler) { ++length; }
String[] scripts = new String[length];
int index = 0;
if (hasUserHandler)
{
scripts[0] = userHandlerScript;
index = 1;
}
if (hasBehaviors)
{
System.arraycopy(data.behaviorScripts.toArray(), 0, scripts, index, numBehaviorScripts);
index += numBehaviorScripts;
}
if (hasHandler)
{
scripts[index] = eventHandlerScript;
}
script = getChainedJS(true, scripts);
}
return script;
}