4

Hello I'm working on a extjs screen that has paging and the method to be used in the request must respond by HTTP POST verb.

I configured my store, so that all the read calls are posts. Realized that, extjs has simply passing the query string for the request payload, and I thought it would be possible to have the parameters separated, just as it would if it uses the params load of a store.

So I wonder if it's possible to have something like {params: {start: 0, page: 1, limit: 20}} in the request payload instead of the query string start = 0 & page = 1 & limit = 20.

I use Extjs 4.2 and Java with RESTEasy.

1 Answers1

0

There isn't any built in functionality for this, but you can extend the store's proxy with the following:

Ext.define('Ext.ux.proxy.ModifiedAjax', {
    extend: 'Ext.data.proxy.Ajax',
    alias: 'proxy.modifiedajax',

    defaultParams: 'param',
    removeDefaultParams: true,

    buildRequest: function(operation) {
        var me = this,
            request,
            defaultParams = me.getParams(operation);

        me.extraParams = me.extraParams || {};
        if (me.defaultParams && defaultParams) {
            me.extraParams[me.defaultParams] = me.applyEncoding(defaultParams);
        }

        var params = operation.params = Ext.apply({}, operation.params, me.extraParams);
        if (me.removeDefaultParams != true) {
            Ext.applyIf(params, defaultParams);
        }

        request = new Ext.data.Request({
            params   : params,
            action   : operation.action,
            records  : operation.records,
            operation: operation,
            url      : operation.url,
            proxy: me
        });
        request.url = me.buildUrl(request);
        operation.request = request;

        return request;
    }
});

and in the store you need to set the proxy's type to 'modifiedajax'.

Alexander.Berg
  • 2,225
  • 1
  • 17
  • 18
  • Thanks for the example code. The modifiedajax works fine, but I need to remove the query string to the end of json, I'll work on it, thanks again – Marcelo Both Oct 08 '13 at 13:38
  • edited the code so you can remove the query string automatically with the `removeDefaultParams: true` property – Alexander.Berg Oct 09 '13 at 09:03