Client-side Firing"

From Documentation
 
(7 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
__TOC__
 
__TOC__
  
In general, an AU request is caused by a widget event (<javadoc directory="jsdoc">zk.Event</javadoc>) 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 <tt>toServer</tt> option (specified in <javadoc directory="jsdoc" method="opts">zk.Event</javadoc>).  In addition, you could invoke <javadoc method="fire()">_global_.zAu</javadoc> explicitly to fire an AU request to the server.  
+
In general, an AU request is caused by a widget event (<javadoc directory="jsdoc">zk.Event</javadoc>) 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 <code>toServer</code> option (specified in <javadoc directory="jsdoc" method="opts">zk.Event</javadoc>).  In addition, you could invoke <javadoc method="fire(_global_.String, zk.Object, _global_.Map, int)" directory="jsdoc">zk.Widget</javadoc> explicitly to fire an AU request to the server.  
  
 
=Fire Event to Widget=
 
=Fire Event to Widget=
Line 22: Line 22:
 
#*The event is declared as [[ZK Client-side Reference/Communication/AU Requests/Server-side Processing#Important_Events|an important event]] (at server).
 
#*The event is declared as [[ZK Client-side Reference/Communication/AU Requests/Server-side Processing#Important_Events|an important event]] (at server).
 
#*The server has registered an event listener (<javadoc type="interface">org.zkoss.zk.ui.event.EventListener</javadoc>) for it.
 
#*The server has registered an event listener (<javadoc type="interface">org.zkoss.zk.ui.event.EventListener</javadoc>) for it.
#Or, the <tt>toServer</tt> option has been specified in <javadoc directory="jsdoc" method="opts">zk.Event</javadoc> of the event. For example,
+
#Or, the <code>toServer</code> option has been specified in <javadoc directory="jsdoc" method="opts">zk.Event</javadoc> of the event. For example,
  
 
<source lang="javascript">
 
<source lang="javascript">
Line 43: Line 43:
 
=Fire Event Directly to Server=
 
=Fire Event Directly to Server=
  
If you would like to fire an event to the server directly, you could invoke <javadoc method="send(zk.Event, int)" directory="jsdoc">_global_.zAu</javadoc>. 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.
+
If you would like to fire an event to the server directly, you could invoke [https://www.zkoss.org/javadoc/latest/jsdoc/_global_/zAu.html#send-zk.Event-int- zAu.send(Event, int)]. 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.
+
The second argument specifies the time to wait before sending the request (unit: milliseconds). If negative, the event won't be sent until another event with a 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 <tt>null</tt> as the target widget of the event.
+
If you would like to send an event to all desktops (in the current browser window), you could specify <code>null</code> as the target widget of the event.
  
 
= What States to Send Back the Server =
 
= What States to Send Back the Server =
Line 55: Line 55:
 
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.
 
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=
 
{{LastUpdated}}
 
{| border='1px' | width="100%"
 
! Version !! Date !! Content
 
|-
 
| &nbsp;
 
| &nbsp;
 
| &nbsp;
 
|}
 
  
 
{{ZKClient-sideReferencePageFooter}}
 
{{ZKClient-sideReferencePageFooter}}

Latest revision as of 04:09, 6 June 2023


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 zAu.send(Event, int). 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 another event with a 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.



Last Update : 2023/06/06

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