private static boolean appendBehaviorsToChain(
      StringBuilder builder,
      FacesContext context,
      UIComponent component,
      List<ClientBehavior> behaviors,
      String behaviorEventName,
      Collection<ClientBehaviorContext.Parameter> params) {

    if ((behaviors == null) || (behaviors.isEmpty())) {
      return false;
    }

    ClientBehaviorContext bContext =
        createClientBehaviorContext(context, component, behaviorEventName, params);

    boolean submitting = false;

    for (ClientBehavior behavior : behaviors) {
      String script = behavior.getScript(bContext);
      if ((script != null) && (script.length() > 0)) {
        appendScriptToChain(builder, script);

        if (isSubmitting(behavior)) {
          submitting = true;
        }
      }
    }

    return submitting;
  }
  private static HandlerType getHandlerType(
      List<ClientBehavior> behaviors,
      Collection<ClientBehaviorContext.Parameter> params,
      String userHandler) {

    if ((behaviors == null) || (behaviors.isEmpty())) {

      if (params.isEmpty()) return HandlerType.USER_HANDLER_ONLY;

      return (userHandler == null) ? HandlerType.SUBMIT_ONLY : HandlerType.CHAIN;
    }

    if ((behaviors.size() == 1) && (userHandler == null)) {
      ClientBehavior behavior = behaviors.get(0);

      if (isSubmitting(behavior) || params.isEmpty()) return HandlerType.SINGLE_BEHAVIOR_ONLY;
    }

    return HandlerType.CHAIN;
  }