Skip to Content
avatar image
Former Member

Syntax of 'Set' Functions

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?

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 22, 2015 at 04:03 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 22, 2015 at 10:15 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.

  • Oct 22, 2015 at 03:38 PM

    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

    Add comment
    10|10000 characters needed characters exceeded