cancel
Showing results for 
Search instead for 
Did you mean: 

HCP User API

0 Kudos

Hello Community,

I'm trying to follow the Tutorial for accessing the HCP User API for html5 .

I do all the three steps.

1) Add the path in the neo-app.json

2) Create the Model in the Controller of my View onInit

3) and then use the code to display the info.

When i run the Code then i only see the defined Labels but not the User info.

Using the Debugger i see that after the initialization the userModel doesn't get filled with the User Data.

I'm using a normal HCP WebIDE and therefore can't deploy the HTML5 Application. Might this be a reason why that doesn't work?

Confused Greetings,

Oliver

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Oliver,

Instead of assigning the model to core framework assign it to view:

onInit:function(){

var userModel = new sap.ui.model.json.JSONModel("/services/userapi/currentUser"); 

this.getView().setModel(userModel, "userapi") ;

}

Refer the below thread for why we attach model to View not Core its not answered but you can get some useful information:

setting Model to sap.ui.getCore not working | SCN

Actually according to me assigning model to core doesn't work because SAPUI5 is now following MVC which means for a view you need to have the Model which can be attached in controller. Earlier SAP doesn't follow much of the MVC framework which makes the model attachment to the core work but now they are following MVC so its not allowing us to attach model to the core.

Cheers

Viplove

0 Kudos

Hey Viplove,

Thanks for your help. Now it works .

I was and am still confused why there is no data in the userModel.

The sample code creates another model, where a currencytype is defined and there i see the Data in the Attribute Odata:

The difference between the UserModel and the oViewModel ist that the userModel links to the User API (using the path in the neo-app.json and thats why the data isn't stored in the Model Object, right?

Is it ok if I add a comment in the original Post by Jamie where I talk about avoiding adding models to the core so others don't make the same mistake?

Answers (1)

Answers (1)

jamie_cawley
Advisor
Advisor
0 Kudos

Hi Oliver,

What do you mean by "normal HCP WebIDE"?  Can you provide your view definition too?

Regards,

Jamie

SAP - Technology RIG

0 Kudos

Hi Jamie,

first thank you for the original Post i am referring too. It's always helpful when somebody translates the cryptic documentation into readable explanations.

Sorry there was a typo in the original post. I wanted to write I'm using the WebIDE for development.

Here is my neo-app.json file.

I am following the official SAPui5 walkthrough so the file has a few views. I want to show the user details in a view called InvoiceList.

I create the userModel in the onInit fuction of the constructor:

In the view i pasted the code you provided into the view.

Running the code i see this:

On the bottom are the added Labels like "User Name" and "Email" but since the UserModel doesn't have any data like shown in my first post the Text fields are empty.

Do i have to do a step before adding the path to the neo-app.json?