Skip to Content
0

Binding data SAPUI5 from Spring (JSON output)

May 22, 2017 at 08:15 AM

91

avatar image
Former Member

Hi all,

I already created service (JSON output) with Spring and I want consume in SAPUI5. I want binding to view. Example: I have a service with url: http://localhost:8080/customer_data :

[{id: "1", name: "aaa"}, {id: "2", name: "bbb"}, {id: "3", name: "ccc"}]

I create model JSON in sapui5:

var model = new JSONModel("http://localhost:8080/customer_data");
this.getView().setModel(model);

I already success with this step. But I want load model with just "customer_data" because maybe I not place this code in localhost, maybe in server or other when I want to deploy. How to fix this problem? So, I want:

var model = new JSONModel("customer_data");

If I use code "new JSONModel(“http://localhost:8080/customer_data”);", is there any problem? Thanks.

Regards,

Bobby

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

avatar image
Former Member May 22, 2017 at 10:02 AM
0

Hi,

For creating jsonModel, try using this format "var oModel =new sap.ui.model.json.JSONModel()". It should work.

For url issue, you will have to use correct URL address where you have placed your data or data file.

Regards,

Aarti

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi,

Yes, I know it. but I have a problem when I load model, I want to load model just with separated url. example:

var oModel = new JSONModel("customer_data");

when I code above, I created model from url: localhost:8080/springproject/customer_data (this url is true, in a question is wrong, I forget put complete url). So, how to fix this problem? how to get ip and port in tomcat 7 with javascript? I not want directly to url: localhost:8080/springproject/customer_data for create the model.

Thanks.

Regards,

Bobby

0
Akhilesh Upadhyay May 23, 2017 at 07:02 AM
0

considering both on the same server, you can form the service url dynamically as below:

var appUrl = window.location; // for example : http://demo.com:8080
var protocol= appUrl.protocol;  //  'http:'
var host = appUrl.hostname;  //  'demo.com'
var port= appUrl.port;      //  8080

var serviceUrl = protocol + "//" + host + ":" + port + "/customer_data";

//now use this serviceUrl in your model.

hope this is what you looking for.

Share
10 |10000 characters needed characters left characters exceeded
Abdul Moh'd Jun 20, 2017 at 03:26 AM
0

Hi, try this:

sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel(), "customerData")
var oModel = sap.ui.getCore().getModel("customerData");
oModel.loadData("http://localhost:8080/customer_data", this.async);

//You'll need to set model to your view before binding it to any controls in that view.
this.getView().setModel(sap.ui.getCore().getModel("customerData", "customerData");
Share
10 |10000 characters needed characters left characters exceeded