google-code-export / gwt-ext-ux

Automatically exported from code.google.com/p/gwt-ext-ux
1 stars 3 forks source link

record.getId() does not work properly when GWTProxy #44

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
My store is built like this
final RecordDef recordDef = new RecordDef(new FieldDef[] { new
StringFieldDef("id"), new StringFieldDef("programname"), new
StringFieldDef("name")});
//this first field will be the id.
ArrayReader reader = new ArrayReader(0, recordDef);

store = new Store(dataProxy,reader, false);

In my code, I will have some actions with the selected record. I tried to
retrieve the record ID by using record.getId(). 
If the dataProxy is JasonProxy, the id is the id from the server
If the dataProxy is GWTProxy, the id is an integer I do not know where it
comes from.

-jason

Original issue reported on code.google.com by jasonzha...@gmail.com on 17 Oct 2008 at 3:51

GoogleCodeExporter commented 9 years ago
i investigate it and found this out:

i you use the GWTProxy then you can also use a custom reader / ArrayReader. if 
you
specify a id column then this column is used. otherwise the autoid code is used 
for
the id. here are the codesnippets which are used for the auto id:

Ext.data.Record = function(data, id){
    this.id = (id || id === 0) ? id : ++Ext.data.Record.AUTO_ID;
    this.data = data;
};

Ext.data.Record.AUTO_ID = 1000;

this record create is caleld from this (look at the marked lines):

Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, {

    readRecords : function(o){
        var sid = this.meta ? this.meta.id : null;  // <-------------------
        var recordType = this.recordType, fields = recordType.prototype.fields;
        var records = [];
        var root = o;
        for(var i = 0; i < root.length; i++){
            var n = root[i];
            var values = {};
            var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ?
n[sid] : null);  // <-------------------
            for(var j = 0, jlen = fields.length; j < jlen; j++){
                var f = fields.items[j];
                var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
                var v = n[k] !== undefined ? n[k] : f.defaultValue;
                v = f.convert(v, n);
                values[f.name] = v;
            }
            var record = new recordType(values, id);   // <-------------------
            record.json = n;
            records[records.length] = record;
        }
        return {
            records : records,
            totalRecords : records.length
        };
    }
});

Original comment by nietz...@gmail.com on 1 Apr 2009 at 9:23

GoogleCodeExporter commented 9 years ago
but note this pitfall:

if you load your records with this id but later you add new records with 
myRecordDef.createRecord( Object[] rowData )
then you dont have a id and it uses the autoid starting with 1000. this then can
mixed with the "normal" id previously readed.

solution:
use myRecordDef.createRecord( String id , Object[] rowData ) with your own id.

Original comment by nietz...@gmail.com on 1 Apr 2009 at 9:31

GoogleCodeExporter commented 9 years ago
to avoid the auto id for your record creation.

use ArrayReader(int id, RecordDef recordDef) to specify a column index with 
your own id.

Original comment by nietz...@gmail.com on 1 Apr 2009 at 9:33