title: Rendering ClientBehaviorHolder
body: <p>I am busy writing my own JSF2 <code>UIComponent</code>s and their relevant renderers. All of my <code>UIComponent</code>s implements <code>ClientBehaviorHolder</code>. What I don't understand is how to really render <code>ClientBehaviorHolder</code>.</p>
  
  <p>For example, the following code illustrates how <code>ClientBehaviorHolder</code> is rendered in Mojarra.</p>
  
  <pre><code>private static void renderHandler(FacesContext context,
                                    UIComponent component,
                                    Collection&lt;ClientBehaviorContext.Parameter&gt; params,
                                    String handlerName,
                                    Object handlerValue,
                                    String behaviorEventName,
                                    String submitTarget,
                                    boolean needsSubmit,
                                    boolean includeExec)
      throws IOException {
  
      ResponseWriter writer = context.getResponseWriter();
      String userHandler = getNonEmptyUserHandler(handlerValue);
      List&lt;ClientBehavior&gt; behaviors = getClientBehaviors(component, behaviorEventName);
  
      // Don't render behavior scripts if component is disabled
      if ((null != behaviors) &amp;&amp; 
          (behaviors.size() &gt; 0) &amp;&amp; 
           Util.componentIsDisabled(component)) {
          behaviors = null;
      }
  
      if (params == null) {
          params = Collections.emptyList();
      }
      String handler = null;
      switch (getHandlerType(behaviors, params, userHandler, needsSubmit, includeExec)) {
  
          case USER_HANDLER_ONLY:
              handler = userHandler;
              break;
  
          case SINGLE_BEHAVIOR_ONLY:
              handler = getSingleBehaviorHandler(context, 
                                                 component,
                                                 behaviors.get(0),
                                                 params,
                                                 behaviorEventName,
                                                 submitTarget,
                                                 needsSubmit);
              break;
  
          case SUBMIT_ONLY:
              handler = getSubmitHandler(context, 
                                         component,
                                         params,
                                         submitTarget,
                                         true);
              break;
  
          case CHAIN:
              handler = getChainedHandler(context,
                                          component,
                                          behaviors,
                                          params,
                                          behaviorEventName,
                                          userHandler,
                                          submitTarget,
                                          needsSubmit);
              break;
          default:
              assert(false);
      }
  
  
      writer.writeAttribute(handlerName, handler, null);
  }
  </code></pre>
  
  <p>For submit handlers, Mojarra adds the <code>mojarra.jsfcljs</code> javascript, <code>UIParameter</code>s and other scripts. For chain handlers, <code>jsf.util.chain</code> is used.</p>
  
  <p>My question is:</p>
  
  <ul>
  <li>How does one determine if we have to render handlers in chain or a single behaviour or user specific handler?</li>
  <li><code>mojarra.jsfcljs</code> is only unique to Mojarra. PrimeFaces have their own implementation, so does Apache Tomahawk. Question is: what does <code>mojarra.jsfcljs</code> do and what is its use? This is so that I can write one for my own? Also, where can I find the implementation of <code>mojarra.jsfcljs</code>?</li>
  <li>What is the specification to render <code>ClientBehaviorHolder</code>?</li>
  </ul>
  
  <p>My sincere thanks in advance.</p>