I watched some tutorials about navigation + passing data between views, but it doesn\'t work in my case. My goal is to achieve the follwing:
The recommended way to pass data between controllers is to use the EventBus
sap.ui.getCore().getEventBus();
You define a channel and event between the controllers. On your DetailController you subscribe to an event like this:
onInit : function() {
var eventBus = sap.ui.getCore().getEventBus();
// 1. ChannelName, 2. EventName, 3. Function to be executed, 4. Listener
eventBus.subscribe("MainDetailChannel", "onNavigateEvent", this.onDataReceived, this);)
},
onDataReceived : function(channel, event, data) {
// do something with the data (bind to model)
console.log(JSON.stringify(data));
}
And on your MainController you publish the Event:
...
//Navigation to the Detail Form
app.to(page,"flip");
var eventBus = sap.ui.getCore().getEventBus();
// 1. ChannelName, 2. EventName, 3. the data
eventBus.publish("MainDetailChannel", "onNavigateEvent", { foo : "bar" });
...
See the documentation here: https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.core.EventBus.html#subscribe
And a more detailed example: http://scn.sap.com/community/developer-center/front-end/blog/2015/10/25/openui5-sapui5-communication-between-controllers--using-publish-and-subscribe-from-eventbus
You can also set local json model to store your data, and use it in the corresponding views. But be sure to initialize or clear it in the right time.
Even though this question is old, the scenario is still valid today (it's a typical master-detail / n-to-1 scenario). On the other hand, the currently accepted solution is not only outdated but also a result of an XY-problem.
is there a more elegant way?
Absolutely. Take a look at this example: https://embed.plnkr.co/F3t6gI8TPUZwCOnA?show=preview
No matter what control is used (App, SplitApp, or FlexibleColumnLayout), the concept is same:
getBindingContext(/*modelName*/)
arguments
in which the passed key(s) are stored. In case of OData, use the API createKey.