Client-side Firing

From Documentation


In general, an AU request is caused by a widget event (Event) that is going to be sent to the server. This happens when the widget event targets a widget that is created at the server, or with the toServer option (specified in Event.opts). In addition, you could invoke Widget.fire(String, Object, Map, int) explicitly to fire an AU request to the server.

Fire Event to Widget

An event can be fired to a widget by the use of Widget.fire(String, Object, Map, int) and Widget.fireX(Event, int). For example,

onCloseClick: function () {
 this.fire('onClose');
}

The event will be propagated to the widget's parent, parent's parent and so on, until all ancestors are notified, or the propagation has been stopped by Event.stop(Map).

After the widget and all of its ancestors are notified, this event is converted to an AU request and sent to the server, if

  1. The widget has a peer component, i.e., the widget was created by ZK Client Engine because of the instantiation of a component at the server[1]. Notice that, to minimize the traffic, ZK Client Engine sends the AU request only if one of the following conditions is satisfied:
  2. Or, the toServer option has been specified in Event.opts of the event. For example,
zAu.send(new zk.Event(wgt, "onFoo", {foo: 'my data'}, {toServer:true}));

For more information, please refer to the next section.


  1. If a widget is created automatically because of a peer component, Widget.inServer will be true.

Fire Event to Desktop

At the client, a desktop (Desktop) is also a widget (Widget). So, firing an event to a desktop is the same as firing to a widget.

If you would like to fire an event to all desktops, please refer to the next section.

Fire Event Directly to Server

If you would like to fire an event to the server directly, you could invoke _global_.zAu. In other words, the event won't go through the target widget's listeners, and will be sent to the server, no matter if it has a peer component or anything else.

The second argument specifies the time to wait before sending the request (unit: milliseconds). If negative, the event won't be sent until anther event with non-negative delay is about to be sent. In other words, if negative, it means the event is deferrable.

If you would like to send an event to all desktops (in the current browser window), you could specify null as the target widget of the event.

What States to Send Back the Server

A component has to synchronize every state affecting the widget's behavior to the client, but the widget is required to send to the server only the state that is changed by the user. For better performance and offline capability, it is not necessary to send back the states changed by the client application.

For example, the change of the value of a textbox widget is better to send back to the peer widget since the user might change it. On the other hand, it is not necessary to send the change of the value of a label widget, since the user won't be able to change it.

Version History

Last Update : 2023/06/06


Version Date Content
     



Last Update : 2023/06/06

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