cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Data Binding to a SimpleForm

TimMuchena
Participant
0 Kudos

I am having issues trying to bind data to a simple form. I am using a mock server and have successfully bind data to a list/table

My manifest.json looks like this


"mock": {

     "dataSource": "mainService"

}

My mockdata(UserDetailsSet.json) looks like this


[{ "ID_PassNum": "cu001",

     "Title": "Mr",

     "Name": "Don",

     "Surname": "Ownery",

     "ResType": "SA",

     "Country": "South Africa"

}]

My SimpleForm fields looks like this

<Input value="{mock>/UserDetailsSet/0/Name}" />

<Input value="{mock>/UserDetailsSet/0/Surname}"/>

I have also tried this

<Input value="{mock>/UserDetailsSet/('00001')/Name}" />

<Input value="{mock>/UserDetailsSet/('00001')/Surname}"/>

What am I missing?

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

check what the model looks like in dev tool

TimMuchena
Participant
0 Kudos

Hi

How do I get reference of the mock model in my controller. Do i need to set it to the view? and if if yes, how do I go about it. Tried to do it but no success so far.

Thanks

junwu
Active Contributor
0 Kudos

i said model...not the json file.....

TimMuchena
Participant
0 Kudos

Hi

If I had a service url I would retrieve the model this way

var oModel = new sap.ui.model.odata.ODataModel(url, true);

...to get the the model. But I have a dummy url specified in the manifest.json file hence the reason I asked how to do it without a proper url

My manifest.json looks like this

"dataSources": {

       "mainService": {

            "uri": "/here/goes/your/serviceUrl/",

            "type": "OData",

            "settings": {

                 "annotations": [],

                 "odataVersion": "2.0",

                 "localUri": "localService/metadata.xml"

            }

       }

  }

....

"mock": {

  "dataSource": "mainService"

  }

Please correct me if I am wrong

junwu
Active Contributor
0 Kudos

model in dev tool.......

D_Chia
Active Participant
0 Kudos

Timothy,

since you configured the model to load from manifest.json it will be created at the Component level.

to "inspect" the model just get to the point where it's already loaded with data and while stopping at any view controller ... issue this in the console

this.getView().getModel("<name of model>")

inspect the 'oData' property from the above result and share it here please.

TimMuchena
Participant
0 Kudos

Hi

Thanks Chia

I tried that in the init event on the view controller since thats the only place that I can thick of where the model is already loaded but its returning undefined

Regards

D_Chia
Active Participant
0 Kudos

not sure if there's an easier way with debugger on.  i would just let the app load completely once and trigger a handler (eg. a button or any click/press of a control) and inspect from there

TimMuchena
Participant
0 Kudos

Hi Chia

Thank you very much for giving me direction. Please see the model below

Regards

junwu
Active Contributor
0 Kudos

check if this one helps

<Input value="{mock>/UserDetailsSet('cu001')/Name}" />

former_member231869
Participant
0 Kudos

Hi Timothy,

            try to understand first you need to set the model first.....not get the model....

sap.ui.getCore().setModel(oModel);

Answers (1)

Answers (1)

former_member231869
Participant
0 Kudos

Hi Timothy,

                 Try this one

<Input value="{mock>/UserDetailsSet/Name}"/>

TimMuchena
Participant
0 Kudos

hi

I tried all the binding paths that i could think of including your suggestion before i posted this post. i'm thinking that i need to do something with the model in the init event of my controller, but what that something is, i dont know

Thank you

former_member231869
Participant
0 Kudos

Follow this might be helpfull....

SAPUI5 SDK - Demo Kit

and u need to set the model like this sap.ui.getCore().setModel(oModel);