Skip to Content
Technical Articles
Author's profile photo Madhusudan H

Master Detail Binding using EventBus in SAP UI5

Requirement:

I had a requirement where on events of View1 I wanted to make some changes in View 2 in Master-Detail page with Nested Views.

 

Advantage

  1. Multiple people can work on same project without facing any issue while merging.
  2. Code is segregate which helps in reducing complexity of program.
  3. Individual view can be used as a plugin.

 

Note :

Here I have created 3 Views one for SplitApp and remaining two views I made it as nested view inside the SplitApp as Master View and Detail View.

 

Step 1: Create one main view as SplitApp follow the as shown in the image

sample%20of%20nested%20view%20in%20SplitApp

sample of nested view in SplitApp

 

Master View

Master%20View

Master View

Detail View

Detail%20View

Detail View

 

Invoking methods of Detail view controller for event occurring in Master View

As per my Requirement this can be achieved by different ways but still will implement it by EventBus

Event Bus is publisher/subscriber design pattern. There will be 2 events one will be a publisher and another will be subscriber.Publisher : This is event which gets triggered on any event of same view.Subscriber: This is event which gets triggered on any event of another View.

 

Code for Master controller  (Publish method)

Publish%20Method

Publish Method

Code for Detail controller (Subscribe method)

Subscribe%20method

Subscribe method

 

Once event is triggered in Master view (publish) an event will be published. All the subscriber (Detail view) events will be triggered (subscribe).

 

Step 2:

Create model with data and configure it in manifest.json file

Data.json

{
    "data":[
        {
            "name":"Madhusudan",
            "city":"Bangalore",
            "Gender":"Male",
            "Salary":"Rs.20000",
            "Designation":"Developer"
        },
        {
            "name":"Ayaz",
            "city":"Hassan",
            "Gender":"Male",
            "Salary":"Rs.30000",
            "Designation":"Developer"
        },
        {
            "name":"Monika",
            "city":"Yamaloka",
            "Gender":"Female",
            "Salary":"Rs.35000",
            "Designation":"Singing and Dancing"
        },
        {
            "name":"Faraz",
            "city":"Ramnagar",
            "Gender":"Male",
            "Salary":"Rs.40000",
            "Designation":"Test Engineer"
        },
        {
            "name":"Sachin",
            "city":"Gulbarga",
            "Gender":"Male",
            "Salary":"Rs.10000",
            "Designation":"System Engineer"
        },
        {
            "name":"Ganesh",
            "city":"Ranebennuru",
            "Gender":"Male",
            "Salary":"Rs.200000",
            "Designation":"Support"
        }
    ]
}

 

Manifest.json

Manifest.json

Manifest.json

 

Final Output

output

output

 

Conclusion

Finally, we done. The same approach can be implement it by in different ways. nested views in master detail with EventBus is one more way. At the same time of event occurring you can pass multiple data as channels as user requirement.

Hope I find this helpful.

 

Thanks and Regards

Madhusudan

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jun Wu
      Jun Wu
      1. I don't understand the mentioned advantage have any relevance here
      2. you should use component's event bus, not core's
      Author's profile photo Simon Coen
      Simon Coen

      Agree! I can only add that the described use-case looks constructed. When you want to display specific data on the detailView depending on a selected item of the MasterView just use the Router.