0
votes

I need to pass addition param to jersey server. But how do I submit my url like ..get/{param1}/{param2}/{param3}

Here is my js file

  Ext.define('bluebutton.view.BlueButton.testing', {
    extend: 'Ext.form.Panel',
    xtype: 'testing',
       requires: [

    'bluebutton.view.BlueButton.TransactionList',
    'bluebutton.view.BlueButton.MemberPopUp',
     'bluebutton.view.BlueButton.MemberDetail',
     'bluebutton.store.BlueButton.MemberList',

    ],
    config: {
     id:'register',
        items :[

              {
                    xtype: 'textfield',
                    name: 'name',
                    label: 'Name'
                },
                {
                    xtype: 'emailfield',
                    name: 'email',
                    label: 'Email'
                },

                 {
                    xtype: 'button',
                    text: 'Send',
                    handler: function(button) {
                        var form = Ext.getCmp('register');
                          values = form.getValues();






//        Select record
        //If load data , restful will using "get",  url will be /users/1
        var User = Ext.ModelMgr.getModel('bluebutton.model.BlueButton.MemberList');
        User.load(123,
         {
            success: function(user) {
            alert(user.get('fullName'));




            }
        }
        );



                    }
                }


        ],


   }

});

Model.js

Ext.define('bluebutton.model.BlueButton.MemberList', {
    extend: 'Ext.data.Model',
    config: {
        idProperty: 'memberModel',
        fields: [
            { name: 'fullName' },
            { name: 'singer' },

        ],

        proxy: {
            type: 'rest',
           url: 'http://localhost:8080/RESTFulExample/rest/json/metallica/get',
            reader: 'json',
            actionMethods: {
                create: 'GET',
                read: 'POST',
                update: 'PUT',
                destroy: 'DELETE'
            },



            reader: {
                type: 'json',

            },

            writer: {
                type: 'json',

            },
        }

    }

});

But now I only able to pass my url like ..get/123 Please guide me some solution.Thanks

2

2 Answers

2
votes

2 things coming to my mind, First do not write proxy inside model definition, instead set it in initialize function of store where you can look at config data and create url on its basis. e.g.

initialize: function() {
        var myId = this.config.uid;
        this.setProxy({
        type: 'rest',
        url: 'http://localhost:8080/RESTFulExample/rest/json/metallica/get/'+myId,
        reader: 'json',
        actionMethods: {
            create: 'GET',
            read: 'POST',
            update: 'PUT',
            destroy: 'DELETE'
        },
        reader: {
            type: 'json',

        },
        writer: {
            type: 'json',

        },
    });
}

and you can pass id to load when you create the store like this:

    var memberStore = Ext.create('bluebutton.store.BlueButton.MemberList', {
        uid : 123
    });

2nd way could be writing your own proxy extending Ext.data.proxy.Rest and implementing buildUrl such that it checks for data and append it to url. e.g.

buildUrl: function(request) {
    var me      = this,
        url     = me.callParent(arguments);
    if(!Ext.isEmpty(someData)){
        url = Ext.urlAppend(url, "data="+someData);
    }
    return url;
}

I hope it helps.

EDIT Sample code for custom proxy which I have used in past to append some token to every request

Ext.define('myapp.proxy.CustomJsonpProxy', {
  extend: 'Ext.data.proxy.JsonP',
  alias: 'proxy.customjsonpproxy',
  buildUrl: function(request) {
    var me      = this,
    url     = me.callParent(arguments);
    if(!Ext.isEmpty(loggedInUserToken)){
      url = Ext.urlAppend(url, "token="+loggedInUserToken);
    }
    return url;
  }
});
0
votes

the below code worked for me....to set a param to an url

myStore.getProxy().getApi().read = myStore.getProxy().getApi().read + param;