Widget Events"

From Documentation
Line 31: Line 31:
 
doClick_: function (evt) {
 
doClick_: function (evt) {
 
     this.fireX(evt);
 
     this.fireX(evt);
     //don't call this.$supers to avoid the event propogation
+
     //don't call this.$supers to avoid the event propagation
 
},
 
},
 
</source>
 
</source>
 +
 +
'''Note''' that this approach is suggested for better performance since no real DOM-level event registration is required (as described in [[ZK Client-side Reference/Notifications/DOM Events|the next section]]).
  
 
==Event Propgation ==
 
==Event Propgation ==

Revision as of 09:21, 20 December 2010


A widget event is the widget-level event (Event).

Like Event at the server side, the widget event can be anything, and can be triggered by a widget or an application to notify a widget-level or application-level event, such as a window has been moved.

In additions, ZK Client Engine intercepts most DOM events and encapsulate them into widgets events, such that it is easier and more efficient for component developers to handle events at widget-level (rather than DOM-level, Event).

Event Listening for Component Developers

ZK Client Engine intercepts most DOM events that are targeting the DOM elements belonging to widgets. It then encapsulates them into widget events, and then invokes the corresponding method of Widget. For example, when the user moves the mouse over a DOM element of a widget, Widget.doMouseOver_(Event) will be called. Similarly, when the user clicks a DOM element of a widget, Widget.doClick_(Event).

Listen by Overriding a Method

Thus, the simplest way to listen a DOM event is to override the corresponding method. For example

doMouseDown_: function (evt) {
    //do whatever you want
    this.$supers('doMouseDown_', arguments); //invoke parent.fireX() and so on
}

where evt is an instance of Event. The original DOM event can be retrieved by use of Event.domEvent, and the original DOM element can be found by use of Event.domTarget (or evt.domEvent.target).

If you want to listen and disable the default behavior, just not to call the super class:

doClick_: function (evt) {
    this.fireX(evt);
    //don't call this.$supers to avoid the event propagation
},

Note that this approach is suggested for better performance since no real DOM-level event registration is required (as described in the next section).

Event Propgation

A widget event will be propagated to the parent widget, parent's parent and so on, until stopped (Event.stop(Map)). Then, if the event is required by the server, it will be sent to the server, and converted to an instance of AuRequest at the server[1].


  1. For more information, please refer to the AU Requests section.

Event Listening for Application Developers

To listen a widget event, you could invoke Widget.listen(Map, int) to listen the widget event you want. However, Widget.listen(Map, int) is designed for applications to listen events at the client. For component development, the method overriding is suggested as described in the previous subsections.

The signature of an event listener is as follows.

function (event) { //an instance of zk.Event
}

Event Firing

To fire a widget event, you could invoke Widget.fire(String, Object, Map, int) or Widget.fireX(Event, int).

Then, the listeners registered with Widget.listen(Map, int) will be invoked one-by-one. Then, it will be sent to the server, if an event listener has been registered at the server or it is an import event[1].

A client-side event listener could stop the sending of a widget event to the server by invoking Event.stop(Map) with {au:true}, such as

evt.stop({au: true});

  1. For more information, please refer to the AU Requests section.

Version History

Last Update : 2010/12/20


Version Date Content
     



Last Update : 2010/12/20

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.