Forum Stats

  • 3,872,132 Users
  • 2,266,392 Discussions
  • 7,911,060 Comments

Discussions

Consuming Rest Webservices in Oracle Jet

Laure Tchagam
Laure Tchagam Member Posts: 49 Red Ribbon
edited Aug 24, 2017 2:40PM in Oracle JET

i am new in Oracle Jet. What i want to achieve, is to Consuming Rest Webservices in Oracle Jet Table.

That is my ViewModell

function CustomerViewModel() {

     var self = this;

    self.DeptCol = ko.observable();

    self.datasource = ko.observable();

    self.serviceURL = '/hr/employees/';

    self.parseDept = function(response) {

        return {empno: response['empno'],

            DepartmentName: response['ename'],

            LocationId: response['job'],

            ManagerId: response['hiredate'],

            mgr: response['mgr'],

            sal: response['sal'],

            comm: response['comm'],

            deptno: response['deptno']};

    };

    self.Department = oj.Model.extend({

        urlRoot: self.serviceURL,

        parse: self.parseDept,

        idAttribute: 'empno'

    });

    self.myDept = new self.Department();

    self.DeptCollection = oj.Collection.extend({

        url: self.serviceURL,

        model: self.myDept

    });

    self.DeptCol(new self.DeptCollection());

}

That is my View

    <table id="table" summary="Department List" aria-label="Departments Table"

           data-bind="ojComponent:{

       component:'ojTable',

       data:datasource,

       columns:[

          {

             headerText:'empno',

             field:'empno'

          },

          {

             headerText:'ename',

             field:'DepartmentName'

          },

          {

             headerText:'job',

             field:'LocationId'

          },

          {

             headerText:'hiredate',

             field:'ManagerId'

          },

          {

             headerText:'mgr',

             field:'mgr'

          },

          {

             headerText:'sal',

             field:'sal'

          },

          {

             headerText:'comm',

             field:'comm'

          },

          {

             headerText:'deptno',

             field:'deptno'

          }

       ]

    }">

    </table>

When i test my Page, it don't show any Errors and the Page is blank. Somebody can help please?

Thank

Tagged:
Laure Tchagam

Best Answer

  • Ben Moroze-Oracle
    Ben Moroze-Oracle Member Posts: 54 Employee
    edited Aug 24, 2017 11:42AM Answer ✓

    Go back to your original url, if it's a REST endpoint. I was pointing out the demo not to steer you to the mockrest server code which you don't have but to point out the setting of the data source property. I would get rid of all loaning of the demos json file and mock rest and just focus on that one data source  line, but using your own data endpoint.

    Laure Tchagam

Answers

  • Ben Moroze-Oracle
    Ben Moroze-Oracle Member Posts: 54 Employee
    edited Aug 24, 2017 10:07AM

    Please see:

    http://www.oracle.com/webfolder/technetwork/jet/jetCookbook.html?component=table&demo=ojCollectionTable

    One immediate issue I see is that you haven't assigned the dataSource property to be anything.  Note the line in the demo linked above:

    self.datasource(new oj.CollectionTableDataSource(self.DeptCol()));

  • Laure Tchagam
    Laure Tchagam Member Posts: 49 Red Ribbon
    edited Aug 24, 2017 10:21AM

    Hey,

    Thank for Answers, When i try than, i have that error

    http://localhost:8383/Sample3/js/mockjax.js net::ERR_EMPTY_RESPONSE

    It Seem as i have not mockjax.js file?

    Can you help please?

  • Ben Moroze-Oracle
    Ben Moroze-Oracle Member Posts: 54 Employee
    edited Aug 24, 2017 10:30AM

    That's just for demo purposes. You need to use your own URL in the collection with a REST endpoint. That's beyond a JET issue

  • Laure Tchagam
    Laure Tchagam Member Posts: 49 Red Ribbon
    edited Aug 24, 2017 10:43AM

    Hey,

    i have already make that.

    define(['ojs/ojcore', 'knockout', 'jquery', 'MockRESTServer', 'ojs/ojknockout', 'promise', 'ojs/ojmodel', 'ojs/ojtable', 'ojs/ojcollectiontabledatasource', 'mockjax'],

    function(oj, ko, $,MockRESTServer) {

     

        function IncidentsViewModel() {

         self.DeptCol = ko.observable();

    self.datasource = ko.observable();

    self.serviceURL = '/hr/employees/';

    self.parseDept = function(response) {

        return {empno: response['empno'],

            DepartmentName: response['ename'],

            LocationId: response['job'],

            ManagerId: response['hiredate'],

            mgr: response['mgr'],

            sal: response['sal'],

            comm: response['comm'],

            deptno: response['deptno']};

    };

    self.Department = oj.Model.extend({

        urlRoot: self.serviceURL,

        parse: self.parseDept,

        idAttribute: 'empno'

    });

    self.myDept = new self.Department();

    self.DeptCollection = oj.Collection.extend({

        url: self.serviceURL,

        model: self.myDept

    });

    self.DeptCol(new self.DeptCollection());

       $.getJSON("/hr/employees/",

                function (data) {

                            new MockRESTServer(data, {id:"empno",

                                url:/^http:\/\/mockrest\/stable\/rest\/Departments(\?limit=([\d]*)?)$/i,

                                idUrl:/^http:\/\/mockrest\/stable\/rest\/Departments\/([\d]+)(?:\\?limit=([\\d]*))$/i}); 

                            self.datasource(new oj.CollectionTableDataSource(self.DeptCol()));

                          });

    That is the error that i get

    Screen Shot 2017-08-24 at 4.41.45 PM.png

  • Ben Moroze-Oracle
    Ben Moroze-Oracle Member Posts: 54 Employee
    edited Aug 24, 2017 11:42AM Answer ✓

    Go back to your original url, if it's a REST endpoint. I was pointing out the demo not to steer you to the mockrest server code which you don't have but to point out the setting of the data source property. I would get rid of all loaning of the demos json file and mock rest and just focus on that one data source  line, but using your own data endpoint.

    Laure Tchagam
  • Laure Tchagam
    Laure Tchagam Member Posts: 49 Red Ribbon
    edited Aug 24, 2017 2:40PM

    Hey,

    it Works now fine. I Remove that Part

    new MockRESTServer(data, {id:"empno",

                                url:/^http:\/\/mockrest\/stable\/rest\/Departments(\?limit=([\d]*)?)$/i,

                                idUrl:/^http:\/\/mockrest\/stable\/rest\/Departments\/([\d]+)(?:\\?limit=([\\d]*))$/i});

    Thanks you

  • User_X1BXO
    User_X1BXO Posts: 1 Employee

    Hey, How did it get resolved? please tell

  • @User_X1BXO as an Oracle employee, please use the internal resources available to you.