I am trying to understand getEventBus()
. Can somebody provide a tutorial or best example where and how we can implement getEventBus()
.

- 3,390
- 3
- 20
- 39

- 179
- 6
- 13
- 29
-
1Possible duplicate of [What is the EventBus in SAPUI5 for?](https://stackoverflow.com/questions/37187748/what-is-the-eventbus-in-sapui5-for) – Boghyon Hoffmann Oct 24 '17 at 14:48
1 Answers
I´ve provided an example to answer another question here.
To put it in a nutshell, you can call sap.ui.getCore().getEventBus()
to get access to the EventBus instance. As it comes from the core it´s the same across all of your views/controllers. The EventBus provides you with the publish/subscribe functionality. This for example enables you to publish an event in Controller A and notify the subscribed Controller B. A simple example largely from my other answer:
Subscribing to the EventBus:
var eventBus = sap.ui.getCore().getEventBus();
eventBus.subscribe("channel1", "event1", this.handleEvent1, this);
Of course you can name your channel and events as you wish. The third parameter indicates the function, that will be called in case of published events. The last paramter is the scope, 'this' will point to in the given function.
Your handleEvent1
function could look like this:
handleEvent1 : function(channel, event, data) {
var customData = data.customData
}
Publishing events to the EventBus:
var customData = {} // anything you eventually want to pass
var eventBus = sap.ui.getCore().getEventBus();
eventBus.publish("channel1", "event1",
{
customData: customData
}
);
If you have more questions about it let me know so I´ll extend it.

- 1
- 1

- 3,390
- 3
- 20
- 39
-
-
What exactly do you want to be more elaborated? Do you have certain questions? – Tim Gerlach Sep 04 '14 at 07:01
-
1Hi @TimGerlach I followed your approach for pub/sub in SapUI5. But my case is a bit different i.e. I want to publish from Application A and want to listen in Application B. In this scenario, it does not works. If one view is sub-view of other it works. – Rusheel Jain May 22 '16 at 13:23
-
1
-
Hi @TimGerlach, what if I want to return some data from 'event1'? Can I access it from eventBus.publish ? – Suhas Bhattu Dec 03 '19 at 05:36