Forum Stats

  • 3,784,367 Users
  • 2,254,929 Discussions
  • 7,880,793 Comments

Discussions

MOOC - With ORDS Restful JSON

Vlam
Vlam Member Posts: 23
edited Sep 26, 2016 8:27AM in Oracle JET

Hi,

I know it is the end of the MOOC, but any help will be appreciated.

I cannot get my application to consume any Oracle exposed webservices, I tried ADF and ORDS.

I am trying to display a table with data from a restful service on the standalone server of ORDS hosted on my local XE database.

When I use the Movie example from http://movieapp-sitepointdemos.rhcloud.com/api/movie it works perfectly.

With Postman I get the following when I invoke the service:

Service URL - http://localhost:8080/ords/cat/core/cat_status

{

  "items": [

    {

      "cat_status_no": 6,

      "cat_status_desc": "DAMAGED"

    },

    {

      "cat_status_no": 3,

      "cat_status_desc": "DECOMMISSIONED"

    },

    {

      "cat_status_no": 1,

      "cat_status_desc": "IN STOCK"

    },

    {

      "cat_status_no": 4,

      "cat_status_desc": "INSTALLED"

    },

    {

      "cat_status_no": 2,

      "cat_status_desc": "PRE_INSTALLED"

    },

    {

      "cat_status_no": 7,

      "cat_status_desc": "SPARE"

    },

    {

      "cat_status_no": 5,

      "cat_status_desc": "STOLEN"

    }

  ],

  "first": {

    "$ref": "http://localhost:8080/ords/cat/core/cat_status?onlyData=true"

  }

}

My code looks like this:

StatusFactory.js

define(['ojs/ojcore'], function(oj) {

    var parseStatus = function(response) {

        return {

            cat_status_no: response['cat_status_no'],

            cat_status_desc: response['cat_status_desc']

        };

    };

    var StatusFactory = {

        resourceUrl: 'http://localhost:8080/ords/cat/core/cat_status',

        // Create a single Status instance.

        createStatusModel: function() {

            var Status = oj.Model.extend({

                urlRoot: this.resourceUrl,

                parse: parseStatus,

                idAttribute: "cat_status_no"

            });

            return new Status();

        },

        // Create a Status collection.

        createStatusCollection: function() {

            var Statuses = oj.Collection.extend({

                url: this.resourceUrl,

                model: this.createStatusModel()

            });

            return new Statuses();

        }

    };

    return StatusFactory;

});

home.js

define(['ojs/ojcore', 'knockout', 'StatusFactory', 'ojs/ojmodel' ,'ojs/ojtable','ojs/ojcollectiontabledatasource'],

function(oj, ko, StatusFactory) {

  var viewModel = {

    statusCollection: StatusFactory.createStatusCollection(),

    dataSource: ko.observable(),

    // Called each time the view is shown to the user.

    initialize: function() {

      this.dataSource(new oj.CollectionTableDataSource(this.statusCollection));

      this.statusCollection.fetch();

    }

  };

  return viewModel;

});

home.html

<div>

  <h1>All Statuses</h1>

    <table id="table"   

        data-bind="ojComponent: {component:'ojTable',

                                 data: dataSource,

                                 columns: [{headerText: 'CAT Status No',  field: 'catStatusNo'},

                                                 {headerText: 'CAT Status Desc',  field: 'catStatusDesc'}

                                       ]}">

    </table>

</div>

Error Log

ailed to load resource: Unexpected end of file from server (09:21:56:218 | error, network)

  at http://localhost:8383/TestApp/js/StatusFactory.js

ojModule failed to load viewModels/home (09:21:56:229 | error)

    at _write (js/libs/oj/v2.1.0/debug/ojcore.js:261:27)

    at error (js/libs/oj/v2.1.0/debug/ojcore.js:157:19)

    at (anonymous function) (js/libs/oj/v2.1.0/debug/ojmodule.js:807:28)

    at (anonymous function) (js/libs/require/require.js:7:145)

    at (anonymous function) (js/libs/require/require.js:23:190)

    at y (js/libs/require/require.js:6:221)

    at emit (js/libs/require/require.js:23:161)

    at (anonymous function) (js/libs/require/require.js:16:32)

    at (anonymous function) (js/libs/require/require.js:7:145)

    at (anonymous function) (js/libs/require/require.js:7:145)

    at (anonymous function) (js/libs/require/require.js:23:190)

    at y (js/libs/require/require.js:6:221)

    at emit (js/libs/require/require.js:23:161)

    at (anonymous function) (js/libs/require/require.js:11:334)

    at y (js/libs/require/require.js:6:221)

    at A (js/libs/require/require.js:11:269)

    at onScriptError (js/libs/require/require.js:30:112)

Error: Script error for "StatusFactory", needed by: viewModels/home

http://requirejs.org/docs/errors.html#scripterror (09:21:56:233 | error)

    at _write (js/libs/oj/v2.1.0/debug/ojcore.js:261:27)

    at error (js/libs/oj/v2.1.0/debug/ojcore.js:157:19)

    at (anonymous function) (js/libs/oj/v2.1.0/debug/ojmodule.js:454:30)

    at (anonymous function) ([native code]:0:0)

    at P (js/libs/es6-promise/es6-promise.min.js:9:2406)

    at x (js/libs/es6-promise/es6-promise.min.js:9:2492)

    at T (js/libs/es6-promise/es6-promise.min.js:9:2309)

    at A (js/libs/es6-promise/es6-promise.min.js:9:1905)

    at a (js/libs/es6-promise/es6-promise.min.js:9:608)

>

Tagged:

Best Answer

  • Vlam
    Vlam Member Posts: 23
    edited Sep 26, 2016 8:27AM Accepted Answer

    Hi,

    The problem was actually StatusFactory was in the wrong directory...

    I put it in the viewModels folder, as soon as I moved it into the root directory it worked perfectly.

    Thanks for the reply

    Regards

    Stefan du Preez

Answers

  • John 'JB' Brock-Oracle
    John 'JB' Brock-Oracle Posts: 2,715 Employee
    edited Sep 24, 2016 4:18PM

    this is just a guess without actually trying to run your code on my end, but it looks like your data is inside of an object called "items".  In your parseStatus function you aren't calling inside of items, but trying to assign the item fields directly.

    I could be wrong, but take a look at what "response" is actually returning when parseStatus is called.

  • Vlam
    Vlam Member Posts: 23
    edited Sep 26, 2016 8:27AM Accepted Answer

    Hi,

    The problem was actually StatusFactory was in the wrong directory...

    I put it in the viewModels folder, as soon as I moved it into the root directory it worked perfectly.

    Thanks for the reply

    Regards

    Stefan du Preez