cancel
Showing results for 
Search instead for 
Did you mean: 

Syntax of 'Set' Functions

0 Kudos

Hi everyone. I have been trying to create a view using 'SET' functions, but no luck. The code below works.


var lco_View = new sap.ui.view(

{    id: "Tasks",

    viewName: "zbc_ui5_app01.Tasks",

    type: sap.ui.core.mvc.ViewType.JS

});

lco_MasterShell.addContent(lco_View);

What is the equivalent using 'Set' Functions:


var lco_View = new sap.ui.view("Tasks");

lco_View.setViewName("zbc_ui5_app01.Tasks");

lco_View.setType(sap.ui.core.mvc.ViewType.JS);

lco_MasterShell.addContent(lco_View);

When I use this code, it gives me an error that 'View type not defined'. How do I get the syntax for 'Set' functions, is there a general rule of thumb. I cannot get the details in the API as well. Or alternatively, can i use the 'setProperty' Function?

Thanks in advance guys.

PS: there is no API reference for node 'SAP.UI.VIEW', is this an alias for another class?

Accepted Solutions (1)

Accepted Solutions (1)

WouterLemaire
Active Contributor
0 Kudos

Hi Jibran,

Here I've a working example:

http://jsbin.com/huhorixabe/edit?html,output

Think you have to switch the id and the name as in my example. Also used sap.ui.jsview instead of sap.ui.view.

Kind regards,

Wouter

0 Kudos

Unbelievable! After breaking my head for hours! Thanks mate.

Answers (2)

Answers (2)

kedarT
Active Contributor
0 Kudos

Hi Jibran,

Use new sap.ui.core.mvc.View to define the constructor for the view and then you can use set functions. More info - SAPUI5 SDK - Demo Kit

Hope this helps

Former Member
0 Kudos

Hi,

That's because you have to define a viewType when you create a view.

As you said, you cannot find the details in the API, so maybe it's not meant to be created like that

Why don't you simply create a sap.ui.core.mvc.JSview? SAPUI5 SDK - Demo Kit

Kind regards,

RW

0 Kudos

Thanks for your reply. I had a feeling that it was a mandatory parameter for the constructor. I have also tried creating "sap.ui.core.mvc.JSview" but I get an "Unable to get property 'viewData' of undefined or null reference" error. And "sap.ui.jsview" also doesn't work.


var lco_View = new sap.ui.core.mvc.JSView("Tasks");

lco_View.setViewName("zbc_ui5_app01.Tasks");

lco_MasterShell.addContent(lco_View);

Any working example of either "sap.ui.jsview" or "sap.ui.core.mvc.jsview"?

Thanks

0 Kudos

Yes I'm trying the same syntax, but it still doesn't seem to work. I keep getting 'failed to load 'Tasks.view.js' from resources/Tasks.view.js: 404 - Not Found' or the other error mentioned above. I have attached both the variants.

This doesn't work.


var lco_View = new sap.ui.jsview("Tasks");

lco_View.setViewName("zbc_ui5_app01.Tasks");

lco_MasterShell.addContent(lco_View);

While this works as mentioned before.


var lco_View = new sap.ui.view(

{    id: "Tasks",

     viewName: "zbc_ui5_app01.Tasks",

     type: sap.ui.core.mvc.ViewType.JS

});

lco_MasterShell.addContent(lco_View);

Although, I have been using the alternative syntax in most of my code, I have been updating my code to use the 'SET' functions. Doing so, I started running into these problems!

Thanks again.