0

I got a xml view with a controller, which I create with sap.ui.view() and then add it to an aggregation of an other view with addDependent(). In the onInit() function of the Controller, I do not have a ownercomponent (this.getOwnerComponent() === undefined //true), since I initialize before I add it as aggregation.

Now I thought to add a Listener (attachEventOnce) and when added to a Aggregation, do the stuff I need.

Is there a event "OwnerComponentChanged" or something like this? even more important: how can I find out, which event there are and which one to take?

Some.controller.js

var oView = sap.ui.view({viewName : "com.example.app.view.dialog", type : "XML"});
this.getView().addDependent(oView);

dialog.controller.js

(§§§ stands for the searched event)

onInit : function(){
    if (this.getOwnerComponent()===undefined) //true
    {
        this.attachEventOnce("§§§", BaseController.prototype.doSomething, this );
    }
}
inetphantom
  • 2,498
  • 4
  • 38
  • 61

1 Answers1

1

As far as I have see there is no event fired when a view is added as a dependent.

In your code however, you are calling the addDependent method. When you do that, you could also fire your own event, message or function. Perhaps it is even better to resolve a Promise?

To find out which events are available for a certain control, you could have a look at the SDK. They're all pretty well documented there. Specifically, Views are documented here, and the list of available events is documented in paragraph "Event summary". To make that list complete, you can also see which events are inherited from lower-level components right underneath that section.

It is of course also always possible to extend the list of events by creating your own version of the View control, which may be a subclass of the actual View control. If you want the addDependent method to fire and event, you should override the addDepdendent method of your vesion. In that override, you could run the regular addDependent logic (using apply), and afterwards fire your custom event handler.

You can find very good information on how to create custom controls in step 34 of the sapui5 walkthough.

Community
  • 1
  • 1
jpenninkhof
  • 1,920
  • 1
  • 11
  • 12