DWRProxy for ExtJs 4

If you are using ExtJs version 4.x for your RIA and DWR for easy to communicate between server-side and client-side (that means “easy ajax”, transform JavaScript object into Java object and vice-versa and so on) in that case you might have noticed that data package of ExtJs4 doesn’t support loading data from DWR method. I’we created Ext.ux.data.DwrProxy class that supports loading data into store from DWR method. Let’s look at sample code:

 * Let's assume that we have already defined App.data.Store 
 * class with its Model class.
var store = Ext.create('App.data.Store', {
    proxy: {
        type : 'dwr',
        /*DWR method that will return data.*/
        dwrFn : MyDWRClass.getRecords,

        /** Function that returns parameters for remote
         * DWR Method for each request.
         getDwrArgs: function(operation, store) {
           var argObj = Ext.apply({}, operation.params);
           argObj.start = operation.start;
           argObj.limit = operation.limit;
            * If server side method takes several parameters
            * then array must be returned.
           return argObj;

       reader : {
           type: 'json',
           root: 'records',
           totalProperty: 'count'

The usage is very likely as DWRProxy classes for ExtJs 3.x and ExtJs 2.x but supports only loading data. I’m ready to implement create, update and destroy methods too if there will be any request for it (I only use DWRProxy just for loading data and paging).

I’ve implemented one additional config option – preprocessResponse that takes response data and fired before server response will be loaded into store. In very specific cases may be you need to do custom modifications to data before it will be load
ed by proxy.reader.

Please look at source of Ext.ux.data.DwrProxy and see more about what and how I’ve done and give me any feedback.

Wish you good luck with ExtJs4 and don’t forget to include DwrProxy.js. 🙂

reader propery of proxy depends on response format and structure. In given case reader can read the following structured JSON object:

  /* because root = 'records' */
  records: [{},{},{},{}...],
  /* because totalProperty = 'count' */
  count: 100

About Mariami Kupatadze
Oracle Certified Master Linkedin: https://www.linkedin.com/in/mariami-kupatadze-01074722/

11 Responses to DWRProxy for ExtJs 4

  1. Jora says:

    Really useful, lost too much time on that, now my problem is solved and btw could u implement create, update and destroy methods too

  2. James Shailes says:

    Thanks very much for this. DwrProxy makes coding new components a breeze and not having it to hand in the new version has meant I haven’t considered moving any code to ExtJs 4. Like Jora, I too would find the create, update and destroy methods useful. Thanks again!

  3. Daniele says:


    I try your implemantion but seems don’t work correctly, in my case, because it assumes that dwr response will be json codify, i notice that in this line of code :

    operation.resultSet = me.getReader().read(response);

    in to ‘read’ method response it is just an array, always in my case.
    So i try to modify your implemantion with this:

    operation.resultSet = me.getReader().readRecords(response);

    but, for Murphi’s law, it doesn’t work anyway.

    You or anybody else has a suggestion.

  4. Giorgi says:

    Yes “it assumes that dwr response will be json codify”, Because DWR gives you ready objects not raw strings. What is response format in you case? If you write details of your case I will help you.

    • Daniele says:

      I resolve my problem, thanks.
      Realy it was my problem 😛 : i coded uncorrectly the grid to show resultset so thought that the response was not red.
      One suggestion, i understand that this part of code :

      reader : {
      type: ‘json’,
      root: ‘records’,
      totalProperty: ‘count’

      It’s formaly constant, independently from the store and its model, in your post can you explain why?

      Thank you very much for your article

      • Giorgi says:

        I updated my post 🙂

        if that config is constant then your server-side data objects are constant too. I mean that all your server-side response objects must have the same named fields (in this case “records” and “count”) whereas you might want different names in different cases.

  5. Harry says:

    thank you

  6. Harry says:

    a array

  7. Alina says:

    I cannot access the JS Files 😦

  8. Chad says:

    Is this file mirrored anywhere else? I’m interested in using it, but the download links are broken.

  9. Anqing says:

    Hi, the link for DWRproxy.js is dead. can you please share the code somewhere?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: