Skip to Content
0
Former Member
May 27, 2014 at 07:25 PM

odata binding

77 Views

Hello, this is my first post. I am building app on demo MyFiorri application and I have problem binding data using ODATA. I difined odata in component.js

jQuery.sap.declare("sap.ui.demo.myFiori.Component");


sap.ui.core.UIComponent.extend("sap.ui.demo.myFiori.Component", {


  createContent : function() {
  // create root view
  var oView = sap.ui.view({
  id : "app",
  viewName : "sap.ui.demo.myFiori.view.App",
  type : "JS",
  viewData : { component : this }
  });
  // set i18n model
  var i18nModel = new sap.ui.model.resource.ResourceModel({
  bundleUrl : "i18n/messageBundle.properties"
  });
  oView.setModel(i18nModel, "i18n");
// // Using OData model to connect against a real service
  var url = "http://localhost:8080/serveris/SERVERIS.svc/";
  var oModel = new sap.ui.model.odata.ODataModel(url, true, "", "");
  oView.setModel(oModel);
  sap.ui.getCore().setModel(oModel);


  // set device model
  var deviceModel = new sap.ui.model.json.JSONModel({
  isTouch : sap.ui.Device.support.touch,
        isNoTouch : !sap.ui.Device.support.touch,
        isPhone : sap.ui.Device.system.phone,
        isNoPhone : !sap.ui.Device.system.phone,
        listMode : sap.ui.Device.system.phone ? "None" : "SingleSelectMaster",
        listItemType : sap.ui.Device.system.phone ? "Active" : "Inactive"
  });
  deviceModel.setDefaultBindingMode("OneWay");
  oView.setModel(deviceModel, "device");
  // done
  return oView;
  }
});


Now, I need to read these data:

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="http://localhost:8080/serveris/SERVERIS.svc/"> <script id="tinyhippos-injected"/>

<id>http://localhost:8080/serveris/SERVERIS.svc/Users</id>

<title type="text">Users</title>

<updated>2014-05-27T18:07:01.403+03:00</updated>

<author> <name/>

</author>

<link href="Users" rel="self" title="Users"/>

<entry> <id>

http://localhost:8080/serveris/SERVERIS.svc/Users(0)

</id>

<title type="text">Users</title>

<updated>2014-05-27T18:07:01.404+03:00</updated>

<category term="serveris.User" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>

<link href="Users(0)" rel="edit" title="User"/>

<link href="Users(0)/TasklistDetails" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/TasklistDetails" title="TasklistDetails"type="application/atom+xml;type=feed"/>

<content type="application/xml"> <m:properties> <d:Login> jonas </d:Login>

<d:Passw>saugus</d:Passw>

<d:UserId>0</d:UserId>

</m:properties>

</content>

</entry>

<entry> <id>

http://localhost:8080/serveris/SERVERIS.svc/Users(1)

</id>

<title type="text">Users</title>

<updated>2014-05-27T18:07:01.405+03:00</updated>

<category term="serveris.User" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>

<link href="Users(1)" rel="edit" title="User"/>

<link href="Users(1)/TasklistDetails" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/TasklistDetails" title="TasklistDetails"type="application/atom+xml;type=feed"/>

<content type="application/xml"> <m:properties> <d:Login> petras </d:Login>

<d:Passw>pass</d:Passw>

<d:UserId>1</d:UserId>

</m:properties>

</content>

</entry>

</feed>


I made login.view.xml and login.controller.js in which i want ta access these data

login.view.xml

<core:View
    controllerName="sap.ui.demo.myFiori.view.login"
  xmlns="sap.m"
  xmlns:l="sap.ui.layout"
  xmlns:core="sap.ui.core" >
  <Page
  title="{i18n>LoginIn}">
  <VBox  
  class="marginBoxContent" >
  <items>
  <Label text="username" />
      <Input       
        id="nameInput"
        type="Text"
        placeholder="enter username ..." />
  <Label text="Pasword" />
   <Input
  id="passwInput"
  type="Password"
  placeholder="enter password..." />
<Button text="Prisijungti"   press="handleContinue" />
  </items>
  </VBox>
  </Page>
</core:View>


login.controller.js

jQuery.sap.require("sap.ui.demo.myFiori.util.Formatter");


sap.ui.controller("sap.ui.demo.myFiori.view.login", {



  handleContinue : function (evt) {
// var authinfo = this.getCore().getModel().getData().Users[0];                In this line I should get data
  var name = this.getView().byId("nameInput").getValue();
    var paswd = this.getView().byId("passwInput").getValue();


  if (name == "authinfo.login" && paswd == "authinfo.passw") {
  var context = evt.getSource().getBindingContext();
  this.nav.to("Master", context);
  }
  else {
  jQuery.sap.require("sap.m.MessageToast");
     sap.m.MessageToast.show("there is no such user or bad login data");

  }
}
});


I hope I clearly described my problem. Thanks in advance