Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ClickHandler vs ItemClickHandler

    I have a menu which contains MenuItem's and I am a bit confused with the two different EventHandler's

    - ClickHandler
    - ItemClickHandler

    Originally I thought the latter would be the sub-class of the former, but that is not true. Instead both are sub-class of EventHandler (Note: EventHandler is Google GWT concept not a SmartGWT concept)

    Is general, is there some general guidelines / documents on how these different SmartGWT handlers are organized or used?

    Thanks!

    #2
    In general, to discover how handlers are used, just look at the docs. There you can see that ItemClickHandler is defined on Menu, and specifically makes available a MenuItem. By contrast, addClickHandler(ClickHandler) is inherited from the superclass Canvas, and has no concept of MenuItems. So you are just seeing the standard object-oriented pattern of more specific handlers being available on subclasses.

    Comment


      #3
      Hi, Thanks for the answer. I did read the documentation but was still confused. However, after I played with the code, I think the following summarizes the difference. Do you agree?

      A Menu can have both a ClickHandler and an ItemClickHandler. The former is for the menu itself being clicked, while the latter is for any MenuItem's under the Menu being clicked.

      A MenuItem can only have a ClickHandler but not an ItemClickHandler. Note, however, that if the MenuItem has a sub menu (which is also just a Menu), then you can add ItemClickHandler to the sub menu (not the MenuItem itself).

      Comment


        #4
        That's all correct.

        Comment


          #5
          Thanks for the confirmation!

          Comment

          Working...
          X