Results 1 to 2 of 2

Thread: ExtJS REST client can't get json data from the RESTful Services

  1. #1
    Sencha User
    Join Date
    Dec 2015
    Posts
    7

    Default Answered: ExtJS REST client can't get json data from the RESTful Services

    I am newbie of ExtJS 5 and this codes are RESTEasy Restful Web Services.

    ==== RESTful Web Services
    package com.aaa.rest;

    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;

    @Path("/services")
    public class RESTEasyServices {

    @GET
    @Path("getJson/{id}")
    @Produces("application/json")
    public Member sayJsonHello(@PathParam("id") String id){
    Member m = new Member();
    m.setId(id);
    m.setPasswd("aaa");
    m.setAge(45);
    m.setName("Joseph");

    return m;
    }
    }

    These are Rest request url and the response json data. The invocation is successful.

    REST url : http://localhost:8080/RESTfulTestWeb...getJson/aupres

    Response Json data : {"id":"aupres","passwd":"aaa","age":45,"name":"joseph"}

    The problem is ExtJS Store object client can not handle the above json data. These are ExtJS client codes

    ===== index.js
    Ext.define('extjs.model.Member', {
    extend: 'Ext.data.Model',

    fields : [{
    name : 'id',
    type : 'string'
    }, {
    name : 'passwd',
    type : 'string'
    }, {
    name : 'age',
    type : 'int'
    }, {
    name : 'name',
    type : 'string'
    }]
    });

    Ext.onReady(function () {

    var members = Ext.create('Ext.data.Store', {

    model : 'extjs.model.Member',
    //autoLoad : true,
    proxy: {
    type: 'rest',
    url : 'http://localhost:8080/RESTfulTestWeb/rest/services/getJson/aupres',
    reader: {
    type: 'json',
    rootProperty: 'id',
    },
    writer: {
    type: 'json'
    },
    listeners: {
    exception: function(proxy, response, operation){
    Ext.MessageBox.show({
    title: 'REMOTE EXCEPTION',
    msg: operation.getError(),
    icon: Ext.MessageBox.ERROR,
    buttons: Ext.Msg.OK
    })
    }
    }

    },
    listeners: {
    load: function(members, operation, success) {
    if(success) {
    alert('response : ' + members.model.length)
    } else {
    alert('it failed')
    }
    }
    }
    })

    var onButtonClick = function() {
    members.load()
    }

    The respose is shown like below
    "response : 0"

    It seems my ExtJS codes fail to contain the json data. I guess the reader and writer attributes of proxy element are wrong. But I have no idea what uri be correct to request the json data.

    Your advice will be deeply appreciated. Thanks in advance.

  2. Hi---

    The rootProperty config in your Reader should correspond to the property in the JSON response that contains the model data.

    So if your response is:

    Code:
    data: {
        {"id":"aupres","passwd":"aaa","age":45,"name":"joseph"}
    }
    Then your rootProperty would be "data"

    Hope that helps--thanks!
    Joel

  3. #2
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Hi---

    The rootProperty config in your Reader should correspond to the property in the JSON response that contains the model data.

    So if your response is:

    Code:
    data: {
        {"id":"aupres","passwd":"aaa","age":45,"name":"joseph"}
    }
    Then your rootProperty would be "data"

    Hope that helps--thanks!
    Joel

Similar Threads

  1. Replies: 2
    Last Post: 3 Jan 2012, 8:13 PM
  2. RESTful Services, JSON
    By Racon in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 16 Jun 2011, 7:14 PM
  3. RESTful web services manual
    By eef in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 29 Dec 2010, 8:14 AM
  4. ExtJS with RESTful Web Services
    By JoeK in forum Ext 2.x: Help & Discussion
    Replies: 9
    Last Post: 5 Dec 2007, 12:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •