Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve view outside the controller

Tags:

sapui5

If I use this.getView() inside the controller of a view I can retrieve it without problems.

How can I retrieve the view if I am outside the controller (e. g. in controller of another view)?

I try sap.ui.core.Core().byId("<name of view>") but it returns undefined.

like image 322
padibro Avatar asked Jun 17 '14 15:06

padibro


People also ask

How do I return a view from a controller?

How do I return a view from a controller? To return a view from the controller action method, we can use View() method by passing respective parameters. return View(“ViewName”) – returns the view name specified in the current view folder (view extension name “. cshtml” is not required.

How do I render a view in another view in MVC?

To create a partial view, right click on the Shared folder -> click Add -> click View.. to open the Add View popup, as shown below. You can create a partial view in any View folder. However, it is recommended to create all your partial views in the Shared folder so that they can be used in multiple views.

Can two controllers have same view?

Yes, put the view in shared folder. This will automatically make view available across multiple controllers.


2 Answers

You can instantiate another view using:

var view = sap.ui.jsview("<name of view>");

If you´re using different view types you can choose the necessary function from here.

To avoid multiple instantiation you could do something like this:

var view = sap.ui.getCore().byId("id");

if (view === undefined) {
    view = sap.ui.jsview("id", "<name of view>");
}

See this for more details regarding view definition/instantiation and IDs.

like image 79
Tim Gerlach Avatar answered Oct 11 '22 12:10

Tim Gerlach


When I create a view i set a id

var theView=sap.ui.xmlview("OperationDetail, "<name of view>");

then i retrieve it by id

var theView = sap.ui.core.Core().byId("OperationDetail");
var myPage=theView.byId("pageOperation");
like image 42
padibro Avatar answered Oct 11 '22 11:10

padibro