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 String getSingleBehaviorHandler(
      FacesContext context,
      UIComponent component,
      ClientBehavior behavior,
      Collection<ClientBehaviorContext.Parameter> params,
      String behaviorEventName) {

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

    String script = behavior.getScript(bContext);

    boolean preventDefault =
        ((isSubmitting(behavior))
            && ("action".equals(behaviorEventName) || "click".equals(behaviorEventName)));

    if (preventDefault) {
      script = script + ";return false";
    }

    return script;
  }
 private static boolean isSubmitting(ClientBehavior behavior) {
   return behavior.getHints().contains(ClientBehaviorHint.SUBMITTING);
 }