Skip to Content
avatar image
Former Member

SAPUI5 Publish and subscribe problem

Hi,

I am using publish/subscribe to pass data from master to detail view.

Master controller.js

var bins = { source: source, destination: destination };
var oEventBus = sap.ui.getCore().getEventBus();
oEventBus.publish("Master", "GetBatches", { bins });

Detail controller.js

onInit: function() {
    this.oInitialLoadFinishedDeferred = jQuery.Deferred();
    var oEventBus = sap.ui.getCore().getEventBus();
    oEventBus.subscribe("Master", "GetBatches", this.onGetBatches, this);

    this.getRouter().attachRouteMatched(this.onRouteMatched, this);		
	},
	onGetBatches : function (sChanel, sEvent, oData) {
//		if(sEvent === "GetBatches"){
			var sourceBin = oData.source;
			var destBin   = oData.destination;
//		} 	
	},

The problem is that when the detail controller gets into onInit, it does not call the function onGetBatches at all but instead it jumps to the onRouteMatched.

Does anyone have an idea, why onGetBatches is not called?

Thanks,

Tim

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Feb 14, 2017 at 09:56 AM

    Hi,

    Why do you want to use the event bus to pass parameters from one view to the other? Why don't you use a navigation parameter when you navigate from master to detail? The walkthrough shows how to do it: https://sapui5.hana.ondemand.com/#docs/guide/2366345a94f64ec1a80f9d9ce50a59ef.html

    Cheers,

    Pierre

    Add comment
    10|10000 characters needed characters exceeded