In addition to the visual representation, a component view usually has some codes running at the client to, say, initialize the view and interact with the user. For Ajax devices, the client codes are written in JavaScript. For sake of convenience, we discuss only Ajax devices here.
Each component that requires the JavaScript codes to run at the client must provide an unique type in the z.type attribute. For example,
<BUTTON id="z_ed_0" z.type="mycomps.MyButton">I am a button</BUTTON>
The syntax is
dir1.dir2.file.Type
The part after the last dot (.) is the name of the type. The part before the last dot is the path of the JavaScript file that must be loaded (to handle the view). ZK use the type as a naming convention to call the proper JavaScript methods. For example, assume the type is Tx. Then, if the zkT.init method is declared, it will be called when ZK is initializing the component at the client.
ZkTp = {}
zkTp.init = function (cmp) {
zk.listen(cmp, "onClick", zkTp.onclick);
}
zkTp.onclick = function (evt) {
var el = Event.element(evt);
...
};
As described in the previous section. the first part of the z.type attribute is the path of the JavaScript to load. For example, assume the z.type attribute is a.b.c.Tx, then ZK will load the file in the path /web/js/a/b/c.js, right before initializing the view.
Notice that the path must be locatable by classpath, and it always stats at /web/js.