Client Activity Watches"
m (→beforeSize) |
m |
||
Line 93: | Line 93: | ||
Notice zWatch's fireDown must be used to fire this event, so only the listeners of descendants of the specified widget will be called. | Notice zWatch's fireDown must be used to fire this event, so only the listeners of descendants of the specified widget will be called. | ||
− | == onBindLevelChange == | + | * Parameters |
− | == onHide == | + | ** ctl.origin - the widget that causes the resizing. If null, it means the whole browser is resized. |
− | == onFloatUp == | + | |
− | == onResponse == | + | === onBindLevelChange === |
− | == onScroll == | + | <code>void onBindLevelMove(<javadoc directory="jsdoc">zk.Widget</javadoc> wgt]];</code> |
− | == onSend == | + | |
− | == onSize == | + | Called if the bind level of a widget (<javadoc directory="jsdoc">zk.Widget</javadoc>'s <code>bindLevel</code>) is changed due to moving from one parent to another. |
− | == onShow == | + | |
+ | Notice it won't be called if it is unbound and bound (i.e., detached and attached). | ||
+ | |||
+ | Notice <javadoc directory="jsdoc">_global_.zWatch</javadoc>'s <code>fire</code> is used, so all listeners are invoked. | ||
+ | |||
+ | === onHide === | ||
+ | <code>void onHide(<javadoc directory="jsdoc">zk.Widget</javadoc> wgt);</code> | ||
+ | |||
+ | Called before a widget is going to become invisible. | ||
+ | |||
+ | Notice <javadoc directory="jsdoc">_global_.zWatch</javadoc>'s <code>fireDown</code> must be used to fire this event, so only the listeners of descendants of wgt will be called. | ||
+ | |||
+ | * Parameters | ||
+ | ** ctl.origin - the widget is becoming invisible | ||
+ | |||
+ | * See Also | ||
+ | ** [[#onVisible]] | ||
+ | |||
+ | === onFloatUp === | ||
+ | <code>void onFloatUp(<javadoc directory="jsdoc">zk.Widget</javadoc> focus);</code> | ||
+ | |||
+ | Called after a widget has gained the focus. It means the 'float' widget that is the parent of the focus widget shall become topmost. | ||
+ | |||
+ | Notice <javadoc directory="jsdoc">_global_.zWatch</javadoc>'s <code>fire</code> is used, so all listeners are invoked. | ||
+ | |||
+ | * Parameters | ||
+ | ** ctl.origin - the widget gains the focus. | ||
+ | |||
+ | === onResponse === | ||
+ | <code>void onResponse();</code> | ||
+ | |||
+ | Called after the response of the AU request has been sent back from the server, and processed. | ||
+ | |||
+ | Notice the <javadoc directory="jsdoc">_global_.zWatch</javadoc>'s <code>fire</code> is used, so all listeners are invoked. | ||
+ | |||
+ | === onScroll === | ||
+ | <code>void onScroll(<javadoc directory="jsdoc">zk.Widget</javadoc> wgt);</code> | ||
+ | |||
+ | Called when the browser window or the specified widget is scrolling. | ||
+ | |||
+ | * Parameter | ||
+ | ** wgt - the widget that is scrolling (i.e., causing the onScroll watch), or null if the whole browser window is scrolling | ||
+ | |||
+ | === onSend === | ||
+ | <code>void onSend(boolean implicit);</code> | ||
+ | |||
+ | Called before sending the AU request to the server. | ||
+ | The implicit argument indicates whether all AU requests being | ||
+ | sent are implicit. | ||
+ | |||
+ | Notice <javadoc directory="jsdoc">_global_.zWatch</javadoc>'s <code>fire</code> is used, so all listeners are invoked. | ||
+ | |||
+ | === onSize === | ||
+ | <code>void onSize(<javadoc directory="jsdoc">zk.Widget</javadoc> wgt);</code> | ||
+ | |||
+ | Called when the browser window and a widget is resized. Notice: <code>beforeSize</code> is called first to reset the size before setting the size in onSize listeners. | ||
+ | |||
+ | Notice that a layout widget (such as Borderlayout and Hbox) must fire both <code>beforeSize</code> and <code>onSize</code> when it resizes. | ||
+ | |||
+ | |||
+ | Notice <javadoc directory="jsdoc">_global_.zWatch</javadoc>'s <code>fireDown</code> must be used to fire this event, so only the listeners of descendants of wgt will be called. | ||
+ | |||
+ | * Parameters | ||
+ | ** ctl.origin - the widget that causes the resizing. If null, it means the whole browser is resized. | ||
+ | |||
+ | === onShow === | ||
+ | <code>void onShow(<javadoc directory="jsdoc">zk.Widget</javadoc> wgt);</code> | ||
+ | |||
+ | Called after a widget has become visible. | ||
+ | |||
+ | Notice <javadoc directory="jsdoc">_global_.zWatch</javadoc>'s <code>fireDown</code> must be used to fire this event, so only the listeners of descendants of wgt will be called. | ||
+ | |||
+ | * Parameters | ||
+ | ** wgt - the widget has become visible | ||
+ | |||
+ | * See Also | ||
+ | ** [[#onHide]] | ||
=Version History= | =Version History= |
Revision as of 03:43, 2 December 2010
In most cases, a widget or an application needs only to listen Event as described in the Client-side Event listening section. However, there are some activities not available as a DOM event (Event) or a ZK event (Event)[1], such as when a widget is becoming invisible, or a window is brought to top. This kind of activity can be listened by so-called watch (zWatch)
Notice that application developers rarely need to access it. It is more for component development.
- ↑ A ZK event is a wrapper of a DOM event to provide more functionality. A DOM event is caused by the browser, and is actually a wrapper class from jQuery to encapsulate the browser's incompatibility.
Listen and Unlisten
To add a watch (i.e., listen to a client activity), you could use zWatch.listen(Map) as follows:
zWatch.listen({
onSize: this,
onShow: this,
onHide: [this, this._onHide]
});
As shown, the key of each entry in the given map is the name of the client activity (aka., the watch name), and the value could be one of the following:
- An object that has a method with the same name. In the above case, this must have the onSize and onSHow methods
- A two-element array, where the first element is the target, and the second is the method
The signature of the method is as follows.
function onWhatever(ctl, arg0, arg1...) {
//ctl.origin: the object passed as the first argument to zWatch.fire or zWatch.fireDown
//ctl.fireDown(something) and ctl.fire(something):
//
}
where ctl is a controller allowing you to have better control of the invocation sequence of the listeners, and arg0 and others are the arguments that passed to zWatch.fire(String, Object, Map) or zWatch.fireDown(String, Object, Map).
The controller has two methods: fire and fireDown, and one field: origin. The fire and fireDown methods are used to fore the remaining listeners (caused by the same invocation of of zWatch.fire(String, Object, Map) or zWatch.fireDown(String, Object, Map)) to be invoked. If your listener doesn't call any of them, the other listeners are called in the same order of registration.
Here is the pseudo code for the controller:
interface Controller {
/** Usually zk.Widget (unless fire and fireDown was called with a different object) */
Object origin;
/** enforce the remaining listeners to be invoked immediately (change the invocation sequence) */
void fire(Object ref, Object...);
/** enforce the remaining listeners to be invoked immediately (change the invocation sequence) */
void fireDown(Object ref, Object...);
}
where ref is optional. If specified, it will invoke only the listeners for the given object (and its descendants if fireDown) that are not invoked yet. If null, it will invokes all the listeners that are not invoked yet.
The origin field (ctl.origin) is the original object (usually a widget, Widget) passed as the first argument when zWatch.fire(String, Object, Map) or zWatch.fireDown(String, Object, Map) was called. In other words, it is the one causes the client activity. It is null if not available.
To unlisten, you could use zWatch.unlisten(Map) as follows:
zWatch.unlisten({
onSize: this,
onShow: this,
onHide: [this, this._onHide]
});
Fire
The client activity is triggered (aka., fired) by either zWatch.fire(String, Object, Map) or zWatch.fireDown(String, Object, Map).
zWatch.fire(String, Object, Map) will invoke the listeners for the target object (the first argument), while zWatch.fireDown(String, Object, Map) will invokes the listeners for the target object and all of its descendants (i.e., the target object's children, grandchildren...).
For example, if a widget resizes itself, it could fire down onSize as follows.
zWatch.fireDown("onSize", wgt);
The target object could be anything as long as the listener recognizes it, but ZK's standard widgets use Widget only.
Client Activities
Here is the list of client activities that you could watch.
beforeSize
It is called right before the browser window or the parent widget is resized.
beforeSize and onSize are fired when the browser window or a widget is resized. beforeSize is fired first, such that the listener could reset style's width or height and the the listener of onSize can change it to the correct size. Notice that it is a must for the TD/TR tag. Otherwise, the onSize's listener cannot change its width/height correctly.
Notice zWatch's fireDown must be used to fire this event, so only the listeners of descendants of the specified widget will be called.
- Parameters
- ctl.origin - the widget that causes the resizing. If null, it means the whole browser is resized.
onBindLevelChange
void onBindLevelMove(Widget wgt]];
Called if the bind level of a widget (Widget's bindLevel
) is changed due to moving from one parent to another.
Notice it won't be called if it is unbound and bound (i.e., detached and attached).
Notice zWatch's fire
is used, so all listeners are invoked.
onHide
void onHide(Widget wgt);
Called before a widget is going to become invisible.
Notice zWatch's fireDown
must be used to fire this event, so only the listeners of descendants of wgt will be called.
- Parameters
- ctl.origin - the widget is becoming invisible
- See Also
onFloatUp
void onFloatUp(Widget focus);
Called after a widget has gained the focus. It means the 'float' widget that is the parent of the focus widget shall become topmost.
Notice zWatch's fire
is used, so all listeners are invoked.
- Parameters
- ctl.origin - the widget gains the focus.
onResponse
void onResponse();
Called after the response of the AU request has been sent back from the server, and processed.
Notice the zWatch's fire
is used, so all listeners are invoked.
onScroll
void onScroll(Widget wgt);
Called when the browser window or the specified widget is scrolling.
- Parameter
- wgt - the widget that is scrolling (i.e., causing the onScroll watch), or null if the whole browser window is scrolling
onSend
void onSend(boolean implicit);
Called before sending the AU request to the server. The implicit argument indicates whether all AU requests being sent are implicit.
Notice zWatch's fire
is used, so all listeners are invoked.
onSize
void onSize(Widget wgt);
Called when the browser window and a widget is resized. Notice: beforeSize
is called first to reset the size before setting the size in onSize listeners.
Notice that a layout widget (such as Borderlayout and Hbox) must fire both beforeSize
and onSize
when it resizes.
Notice zWatch's fireDown
must be used to fire this event, so only the listeners of descendants of wgt will be called.
- Parameters
- ctl.origin - the widget that causes the resizing. If null, it means the whole browser is resized.
onShow
void onShow(Widget wgt);
Called after a widget has become visible.
Notice zWatch's fireDown
must be used to fire this event, so only the listeners of descendants of wgt will be called.
- Parameters
- wgt - the widget has become visible
- See Also
Version History
Version | Date | Content |
---|---|---|