Business Console 10.7 | webMethods Business Console Documentation | Developing Gadgets for Business Console | Getting Started | Communicating Between Two Gadgets
 
Communicating Between Two Gadgets
 
Implementing Communication Between Gadgets
Communication between gadgets is possible by using a custom JavaScript service called EventBus provided by the gadget framework. Each gadget can act as an event subscriber or publisher or both. This section provides basic information for using the EventBus service.
To make a gadget trigger events, the fireEvent method of EventBus is used. The first argument is the Event Name, the second argument is the payload or the data to be passed, and the third argument is an optional context.
this.eventBus.fireEvent("SOME_EVENT_NAME", "Some Event!");
To make a gadget receive events, define the listener in the defineListener block in the controller of the subscribing gadget and then put the handling logic in the _handleEvents block.
this.eventBus.addEventListener("SOME_EVENT_NAME",this._handleEvents.bind(this));
_handleEvents:function(eventType,payload,context){
/* Logic to handle events
*/
switch(eventType){
case "SOME_EVENT_NAME":
/* Add Event Handling Logic for GLOBAL_EVENT */
this.$scope.exampleHandleEventAction(payload); //ONCE EVENT
IS RECEIVED , INVOKE THE exampleHandleEventAction function on $scope.
break;
}
},