2 Replies Latest reply on Jul 21, 2011 10:24 PM by bleathem

    Making sense of events in the CDK

    bleathem

      I've been spending a lot of time with the CDK this week.  I've been able to figure out how it all fits together with the bits of existing documentation, and looking over some examples of other RichFaces components. However, there is one piece that still leaves me confused, and that is this line in the select.template.xml file:

      <cdk:scriptOption attributes="onbegin oncomplete onerror onbeforedomupdate onchange onblur onselectitem onfocus onlistshow onlisthide"
                              wrapper="eventHandler" />
      

       

      what does this do?  Why are some of the events defined in AbstractSelectComponent present in this scriptOption, and others are not?

       

      The CDK tag docs state that these attributes are a:

      Space-separated list of attributes to be added to the hash.

      And the wrapper is:

      Optional wrapper around value.

       


      eventHandler: value ->

           function (event) { value }

      So these attributes are added to the script hash, wrapped to make them functions.  What do they then do?

       

      The only thing I can guess, is that if I define my component with an attribute that corresponds to one of these events, that the value of that attribute will be passed into the generated javascipt.  Thereby allowing me to define a custom event handler.  Why I think this is not correct, however, is what of the other event attibutes defined in the AbstractComponent?  If my understanding is correct, then there values would not be passed through to the script.

       

      I'd appreciate any insight anyone can offer as to the purpose of thise scriptOption tag.

       

      Thanks!

        • 1. Re: Making sense of events in the CDK
          nbelaevski

          Hi Brian,

           

          >> The only thing I can guess, is that if I define my component with an attribute that corresponds to one of these events,

          >> that the value of that attribute will be passed into the generated javascipt.  Thereby allowing me to define a custom event handler. 

           

          That's exactly how it works.

           

          >> Why I think this is not correct, however, is what of the other event attibutes defined in the AbstractComponent?

           

          They are handled in another place, e.g. wriiten as inline script by pass-through encoder. The difference there is that some HTML events can be used directly (like 'onclick') but for the other ones additional logic is implemented in component JavaScript code (e.g. onchange of input number slider is triggered by either text input update or slider handle position changed so we should trigger event for both cases).

          • 2. Re: Making sense of events in the CDK
            bleathem

            Thanks Nick, that helps a lot!