on 05-18-2016 1:23 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
Hi Oliver,
What do you mean by "normal HCP WebIDE"? Can you provide your view definition too?
Regards,
Jamie
SAP - Technology RIG
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.