zk
Class Event

java.lang.Object
  extended by zk.Object
      extended by zk.Event

public class Event
extends Object

The class representing a widget event (aka., a ZK event). A widget event is the widget-level event that a widget can fire and the client application can listen.

On the other hand, a DOM event (Event) is the low-level event related to DOM elements. It is usually listened by the implementation of a widget, rather than the client application.

In additions, zWatch is an utility to manage the system-level events, and both the client application and the widget implementation might listen.

To fire a widget event, use Widget.fire(_global_.String, zk.Object, _global_.Map, int). To listen a widget event, use Widget.listen(_global_.Map, int).

See Also

Common Key Codes:

BACKSSPACE8 TAB9 ENTER13 SHIFT16 CTRL17
ALT18 ESC27 PGUP33 PGDN34 END35
HOME36 LEFT37 UP38 RIGHT39 DOWN40
INS45 DEL46 F1112


Field Summary
 boolean auStopped
          Indicates whether to stop the sending of the AU request to the server.
 Widget currentTarget
          Indicates the target which is handling this event.
 Object data
          The data which depends on the event.
 Event domEvent
          The DOM event that causes this widget event, or null if not available.
 boolean domStopped
          Indicates whether to stop the native DOM event.
 DOMElement domTarget
          The DOM element that the event is targeting, or null if not available.
 String name
          The event name, such as 'onChange'.
 Map opts
          The options (never null).
 boolean stopped
          Indicates whether the event propagation is stopped.
 Widget target
          The target widget (readonly).
 
Fields inherited from class zk.Object
$class, $oid
 
Method Summary
 void $init(Widget target, String name, Object data, Map opts, Event domEvent)
          Constructor.
 void addOptions(Map opts)
          Adds the additions options to opts.
 void stop(Map opts)
          Stop the event propagation.
 
Methods inherited from class zk.Object
$init, $instanceof, $super, $super, $supers, $supers, afterInit, isAssignableFrom, isInstance, proxy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

target

public Widget target
The target widget (readonly).

See Also:
currentTarget

currentTarget

public Widget currentTarget
Indicates the target which is handling this event.

By default, an event will be propagated to its parent, and this member tells which widget is handling it, while #target is the widget that the event is targeting.

See Also:
target

name

public String name
The event name, such as 'onChange'. The data which depends on the event. Here is the list of Event Data.

However, if data is an instance of Map, its content is copied to the event instance. Thus, you can access them directly with the event instance as follows.


onClick: function (evt) {
  if (evt.altKey) { //it is the same as evt.data.altKey
  }
}


data

public Object data
The data which depends on the event. Here is the list of Event Data.

Data can be any javascript Object. You can bring Number, String or JSON object to server side with it.

The javascript JSON object will be transfered to org.zkoss.json.JSONObject at server side as the following:


// at client side
var json = { "aa" : [{"a11":"11", "a12":12},{"a21":"21","a22":22.2}],                                  
    "bb":[{"b11":"31","b12":"32"},{"b21":"41","b22":"42","b23":43}]
  },
  data = {jsonObject:json};

// at server side
final JSONObject jsonObject = (JSONObject)data.get("jsonObject"); // get JSONObject
// will output "22.2"
System.out.println(((JSONObject)((JSONArray)jsonObject.get("aa")).get(1)).get("a22"));
// will output "class java.lang.Double"
System.out.println(((JSONObject)((JSONArray)jsonObject.get("aa")).get(1)).get("a22").getClass());

However, if data is an instance of Map, its content is copied to the event instance. Thus, you can access them directly with the event instance as follows.


onClick: function (evt) {
  if (evt.altKey) { //it is the same as evt.data.altKey
  }
}

Refer to ZK Client-side Reference: AU Requests: Server-side Processing.


opts

public Map opts
The options (never null).

Allowed properties:


domEvent

public Event domEvent
The DOM event that causes this widget event, or null if not available.


domTarget

public DOMElement domTarget
The DOM element that the event is targeting, or null if not available.


stopped

public boolean stopped
Indicates whether the event propagation is stopped.

See Also:
stop(_global_.Map), auStopped, domStopped

auStopped

public boolean auStopped
Indicates whether to stop the sending of the AU request to the server.

See Also:
stop(_global_.Map), stopped, domStopped

domStopped

public boolean domStopped
Indicates whether to stop the native DOM event.

See Also:
stop(_global_.Map), stopped, auStopped
Method Detail

$init

public void $init(Widget target,
                  String name,
                  Object data,
                  Map opts,
                  Event domEvent)
Constructor.

Parameters:
target - the target widget.
name - the event name, such as onClick
data - [optional] the data depending on the event.
opts - [optional] the options. Refer to opts
domEvent - [optional] the DOM event that causes this widget event.

addOptions

public void addOptions(Map opts)
Adds the additions options to opts.

Parameters:
opts - a map of options to append to #opts

stop

public void stop(Map opts)
Stop the event propagation.

evt.stop();
evt.stop({propagation:true}); //stop only the event propagation (see below)
evt.stop({au:true}); //stop only the sending of the AU request

If you want to revoke the stop of the event propagation, you can specify {revoke:true} to the opts argument.


evt.stop({progagation:true,revoke:true}); //revoke the event propagation

Notice that the event won't be sent to the server if stop() was called.

Parameters:
opts - [optional] control what to stop. If omitted, the event propagation (stopped) and the native DOM event (domStopped) are both stopped (but not auStopped). For fine control, you can use a combination of the following values:
  • revoke - revoke the stop, i.e., undo the last invocation of stop(_global_.Map)
  • propagation - stop (or revoke) the event propagation (stopped).
  • dom - stop (or revoke) the native DOM event (domStopped).
  • au - stop (or revoke) the sending of the AU request to the server (auStopped). Notice that, unlike the propagation and dom options, the sending of AU requests won't be stopped if opts is omitted. In other words, to stop it, you have to specify the au option explicitly.


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo