About this task
Do the following steps to implement the event mechanism:
- Define the event handler in widget Java script:
this.handler1 = function() {
alert(‘handler1');
}
- Listen the event in widget using one of the following methods:
- Code directly.
this.iContext.addEventListener('eventName1',false, this.handler1,this);
BTT Web
2.0 provides multiple parameters for you to listen events.Table 1. Listen
eventAPI |
Input |
Output |
this.iContext.addEventListener |
P1,P2, P3,…Pn |
P1 is the event id. P2 is a flag that decides
whether this event can be subscribed by other widgets. True denotes
that this event you listen is private and you cannot receive this
event, but false means the event is public and this widget can listen
and receive it. P3 is the handler for this listener. P4 is the scope
and normally we use ‘this' for this widget, and P5…Pn are the
input parameter of handler |
- :Configured in .xml file.
You also can declare the event in
widget definition XML file:
......
<iw:event id="eventName1" onEvent="handler1 " isPrivate=”false” />
<iw:content mode="view">
</iw:content>
</iw:iwidget>
- Invoke the event:
this.iContext.fireEvent('eventName1', false);
BTT Web
2.0 provides multiple parameters for you to fire event:
Table 2. Fire
eventAPI |
Input |
Output |
this.iContext.fireEvent |
P1,P2, P3,…Pn |
P1 is the event id. P2 is a flag that decides
whether this event can be subscribed by other widgets. True denotes
that this event is private, but false means the event is public and
other widgets can listen it.P3…Pn are the input parameter of handler |