cancel
Showing results for 
Search instead for 
Did you mean: 

How to communicate an event from a sub view back to the parent view?

Former Member
0 Kudos

In a previous discussion I asked about how to swap out 2 separate areas in my application on the same page.

A poster (I think it was Andreas) suggested instead of using OverlayContainer (which either relies on a Shell or covers up the entire iFrame which was not good since I can't cover up a banner) that I just do this in 2 DIV's.

So I have one XML view that contains these 2 DIV's. The first DIV is the main one.

In the second DIV I was able to "include" another XML view (using the XMLView tag and giving it the view name) which is pretty cool.

The only thing is that in that second DIV's XML view there is a close button and I need to be able send an event from that view's controller back to the first DIV's controller so it can show the first DIV and hide the second DIV.

I tried to access them by doing this in the second DIV's controller but it did not work:

this.getView().getParent().byId("firstDIV");

Thanks,

Erich

Accepted Solutions (1)

Accepted Solutions (1)

former_member189945
Contributor
0 Kudos

Hi Erich,

You can call a method of another Controller directly this way:

sap.ui.controller("namespace.Controllername").method();

Another, and more decoupled, option would be to use eventing and sap.ui.core.EventBus. You can find more info on this SCN thread:

Former Member
0 Kudos

Hi Kimmo,

You are right that technique you showed does allow me to call a function in another controller.

However in the function in the other controller that is called I try and do this:

var myContent = this.getView().byId("myContent");

And in the debugger the this.getView() comes back as undefined.

Is there a way to re-establish the view for the controller that was called?

Thanks,

Erich

former_member189945
Contributor
0 Kudos

It could be that "this" does not refer to the controller whose method that is, but the other controller. Can you get reference with

var myContent = sap.ui.controller("namespace.Controllername").getView().byId("myContent");



Former Member
0 Kudos

I ended up just making the variables that I needed global and that worked although not a great practice. I am looking to do this with an OverlayContainer instead of DIVs now.

Answers (0)