1. #1
    Sencha Premium Member seek's Avatar
    Join Date
    Sep 2008
    Location
    Italy
    Posts
    112
    Vote Rating
    1
    seek is on a distinguished road

      0  

    Default Unanswered: DWR & Sencha Touch 2

    Unanswered: DWR & Sencha Touch 2


    Hi all,
    what's the best way to read DWR data with Sencha Touch 2?
    I'm trying to adapt the library that I use in my middleware (don't remember where I found it, maybe on the forum).
    But it was written to ExtJS 3.x, and the differences between frameworks are taking me more time than I probably need to rewrite it, or what I would like to learn more about using Sencha Touch 2 and understand that this is not a necessary job.

    Tips? Guidelines?
    Thanks all!

    PHP Code:
    Ext.define('Ext.ux.DwrReader', {
      
    extend'Ext.data.JsonReader',
      
    alternateClassName'Ext.data.DwrReader',
      
    alias'reader.dwrjson',
      
    getResponseData: function (response) {
        var 
    responseText response;
        
    // Handle an XMLHttpRequest object
        
    if (response && response.responseText) {
          
    responseText response.responseText;
        }
        
    // Handle the case where data has already been decoded
        
    if (typeof responseText !== 'string') {
          return 
    responseText;
        }
        var 
    data;
        try {
          
    data this.readRecords(responseText);
        } catch (
    ex) {
          
    /**
           * @event exception Fires whenever the reader is unable to parse a response.
           * @param {Ext.data.reader.Xml} reader A reference to this reader
           * @param {XMLHttpRequest} response The XMLHttpRequest response object.
           * @param {String} error The error message.
           */
          
    this.fireEvent('exception'thisresponse'Unable to parse the JSON returned by the server: ' ex.toString());
          
    Ext.Logger.warn('Unable to parse the JSON returned by the server: ' ex.toString());
        }
        
    //<debug>
        
    if (!data) {
          
    this.fireEvent('exception'thisresponse'JSON object not found');
          
    Ext.Logger.error('JSON object not found');
        }
        
    //</debug>
        
    return data;
      },
      
    getJsonAccessor: function () {
        var 
    re = /[\[\.]/;
        return function (
    expr) {
          try {
            return (
    re.test(expr)) ? new Function("rec""defaultValue""try{with (rec) return " expr " || defaultValue;}catch(e){return defaultValue;}") : function (recdefaultValue) {
              try {
                return 
    rec[expr] || defaultValue;
              } catch (
    e) {
                return 
    defaultValue;
              };
            };
          } catch (
    e) {};
          return 
    Ext.emptyFn;
        };
      },
      
    readRecords: function (o) {
        
    /**
         * After any data loads, the raw JSON data is available for further custom processing.
         * @type Object
         */
        
    this.jsonData o;
        var 
    this.config//this.meta; commented old lib
        
    var Record this.getModel(); //this.recordType;  commented old lib
        
    var Record.getFields(); //Record.prototype.fields;  commented old lib
        
    var fi f.all//f.items; commented old lib
        
    var fl f.length;
        
    //Generate extraction functions for the totalProperty, the root, the id, and for each field
        
    if (!this.ef) {
          if (
    s.totalProperty) {
            
    this.getTotal this.getJsonAccessor(s.totalProperty);
          };
          if (
    s.successProperty) {
            
    this.getSuccess this.getJsonAccessor(s.successProperty);
          };
          
    this.getRoot s.root this.getJsonAccessor(s.root) : function (p) {
            return 
    p;
          };
          if (
    s.id) {
            var 
    this.getJsonAccessor(s.id);
            
    this.getId = function (rec) {
              var 
    g(rec);
              return (
    === undefined || === "") ? null r;
            };
          } else {
            
    this.getId = function () {
              return 
    null;
            };
          };
          
    this.ef = [];
          for (var 
    0fli++) {
            
    fi[i];
            var 
    map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping f.name;
            
    this.ef[i] = this.getJsonAccessor(map);
          };
        };
        var 
    root this.getRoot(o),
          
    root.length,
          
    totalRecords c,
          
    success true;
        if (
    s.totalProperty) {
          var 
    parseInt(this.getTotal(o), 10);
          if (!
    isNaN(v)) {
            
    totalRecords v;
          };
        };
        if (
    s.successProperty) {
          var 
    this.getSuccess(o);
          if (
    === false || === 'false') {
            
    success false;
          };
        };
        var 
    records = [];
        for (var 
    0ci++) {
          if (
    root[i] instanceof Array) {
            var 
    root[i][(root[i].length 1)];
          } else {
            var 
    root[i];
          };
          var 
    values = {};
          var 
    id this.getId(n);
          for (var 
    0flj++) {
            
    fi[j];
            try {
              var 
    this.ef[j](nf.defaultValue);
              
    values[f.name] = f.convert(v);
            } catch (
    e) {
               
    values[f.name] = "";
            };
          };
          var 
    record = new Record(valuesid);
          
    record.json n;
          
    records[i] = record;
        };
        return {
          
    successsuccess,
          
    recordsrecords,
          
    totalRecordstotalRecords
        
    };
      }
    }); 

  2. #2
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    618
    Vote Rating
    29
    Answers
    67
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    Define DWR

  3. #3
    Sencha Premium Member seek's Avatar
    Join Date
    Sep 2008
    Location
    Italy
    Posts
    112
    Vote Rating
    1
    seek is on a distinguished road

      0  

    Default


    Quote Originally Posted by bluehipy View Post
    Define DWR
    Sorry bluehipy, but...

  4. #4
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    618
    Vote Rating
    29
    Answers
    67
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    So you probably mean the

    DWR, or Direct Web Remoting, is a Java open source library that helps developers write web sites that include Ajax technology. It allows...en.wikipedia.org/wiki/DWR_(Java)





    Is DWR any different than communicating with other server side type?

    I see you try to extend a json reader but I don't see what you want to add to it.

    http://docs.sencha.com/touch/2-0/#!/...ta.reader.Json

  5. #5
    Sencha Premium Member seek's Avatar
    Join Date
    Sep 2008
    Location
    Italy
    Posts
    112
    Vote Rating
    1
    seek is on a distinguished road

      0  

    Default


    Yes, you are right!
    DWR returns something like this:
    Code:
     //#DWR-INSERT
    dwr.engine.remote.handleNewScriptSession("725C47359D5D9F1E486321351E5DACC0");
    //#DWR-REPLY
    var s0={};var s1={};var s2={};var s3={};s0.codMa="CFCA";
    s1.des="Conf";s1.gesAcc="N";
    s2.des="Unica";s2.gesAcc="Y";
    s3.des="Spediz";s3.gesAcc="N";
    dwr.engine.remote.handleCallback("18","0",{items:[[s0,s1,{desZo:"Conf",id:{codMa:"CFCA",codZo:"CFCACN"}}],[s0,s2,{desZo:"Stock",id:{codMa:"CFCA",codZo:"CFCAPK"}}],[s0,s3,{desZo:"Sped",id:{codMa:"CFCA",codZo:"CFCASP"}}]],totalCount:3});
    but I'm trying to decode something like this:
    Code:
    var s0={};var s1={};var s2={};var s3={};s0.codMa="CFCA";
    s1.des="Conf";s1.gesAcc="N";
    s2.des="Unica";s2.gesAcc="Y";
    s3.des="Spediz";s3.gesAcc="N";
    {items:[[s0,s1,{desZo:"Conf",id:{codMa:"CFCA",codZo:"CFCACN"}}],[s0,s2,{desZo:"Stock",id:{codMa:"CFCA",codZo:"CFCAPK"}}],[s0,s3,{desZo:"Sped",id:{codMa:"CFCA",codZo:"CFCASP"}}]],totalCount:3};
    I use the DWR API to get the data in this format.

    Tnx anyway
    Seek

  6. #6
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    618
    Vote Rating
    29
    Answers
    67
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    Probable what you want to do is to create a DWR proxy with a DWR reader and a DWR writer, in each of them you will need to wrap all their methods over the dwr.engine.remote and route response to base callbacks.

    However your problem is presented vague, in my opinion.

Thread Participants: 1

Tags for this Thread