Search code examples
sapui5

How to retrieve view from controller of another view?


I am just wondering how can I get one of the UI5 views in an application.

I know there is a method:

sap.ui.jsview(); // in case the view is written in JavaScript

But the problem with this method is: if you assign ID for any of the controls and you have already inflated this view, you get an error.

So I want to know how to check if the view already exists and then if yes return that existing view, otherwise create the view with the corresponding API such as the above one.

I also know in the control for view I can go

this.getView();

But as I said, how to get this view from another view?


Solution

  • I am not quite understanding your question

    With managed object id's are unique, so if you try and create the same view twice you will get an error.

    when you create your view the easiest way to access it is via an Id

     sap.ui.jsview("view1",'testapp.view.view1');
     sap.ui.getCore().byId('view1');
    

    NB. views should not talk to anyone other than their controller A terrific Model View Controller (MVC) diagram