0
votes

I'm using Smart GWT 2.3.0 in any browser.

I have a listgrid simple only with data. And when I create new register it doesn't update my id.

I read the faq problem about that, and I think I have everything correct.

the code of data source is:

DataSource ds = null;
    try {
        ds = new DataSource();
        ds.setDataURL("do");
        ds.setController(controller);

        DataSourceTextField nombre = new DataSourceTextField("nombre", 
            "Nombre", 50, true);
        DataSourceTextField codigo = new DataSourceTextField("codigo", 
            "Código", 50, true);
        DataSourceTextField id = new DataSourceTextField("id", 
            "Identificador", 50);
        id.setPrimaryKey(Boolean.TRUE);
        id.setCanEdit(Boolean.FALSE);

        ds.setFields(id, codigo, nombre);

The console result is:

    16:43:29.808:KPR3:DEBUG:gridEdit:isc_ListGrid_1:showing

inline editor at: 3,2, will focus: true 16:43:31.385:KPR5:INFO:gridEdit:isc_ListGrid_1:cellEditEnd: ending editing, completion event: enter 16:43:31.386:KPR5:DEBUG:gridEdit:isc_ListGrid_1:change detection: newValues: {codigo: "PRUEBA", nombre: "Prueba"}, oldValues: undef 16:43:31.390:KPR5:DEBUG:gridEdit:isc_ListGrid_1:At field: codigo applying validators: [ {type: "isString", typeCastValidator: true, _generated: true, defaultErrorMessage: "Must be a String."}, {type: "required", defaultErrorMessage: undef, errorMessage: "Field is required"} ] to value:PRUEBA 16:43:31.390:KPR5:INFO:gridEdit:isc_ListGrid_1:validateFieldValue, newValue: "PRUEBA", passed validation: true, resultingValue: null 16:43:31.392:KPR5:DEBUG:gridEdit:isc_ListGrid_1:At field: nombre applying validators: [ {type: "isString", typeCastValidator: true, _generated: true, defaultErrorMessage: "Must be a String."}, {type: "required", defaultErrorMessage: undef, errorMessage: "Field is required"} ] to value:Prueba 16:43:31.393:KPR5:INFO:gridEdit:isc_ListGrid_1:validateFieldValue, newValue: "Prueba", passed validation: true, resultingValue: null 16:43:31.393:KPR5:INFO:gridEdit:isc_ListGrid_1:Saving newValues '{codigo: "PRUEBA", nombre: "Prueba"}' 16:43:31.996:XRP3:DEBUG:ResultSet:isc_ResultSet_1 (created by: isc_ListGrid_1):dataSource data changed firing 16:43:31.997:XRP3:INFO:ResultSet:isc_XDataSource_3:dsResponse for successful operation of type add did not return updated record[s]. Using submitted request data to update ResultSet cache. 16:43:31.997:XRP3:DEBUG:ResultSet:isc_XDataSource_3:Submitted data to be integrated into the cache:[ {codigo: "PRUEBA", nombre: "Prueba"} ] 16:43:31.997:XRP3:INFO:ResultSet:isc_ResultSet_1 (created by: isc_ListGrid_1):updating cache in place after operationType: add, allMatchingRowsCached true 16:43:31.997:XRP3:INFO:ResultSet:isc_ResultSet_1 (created by: isc_ListGrid_1):Updating cache: operationType 'add' submitted by 'isc_ListGrid_1',1 rows update data: [ { codigo: "PRUEBA", nombre: "Prueba"} ] 16:43:31.998:XRP3:INFO:ResultSet:isc_ResultSet_1 (created by: isc_ListGrid_1):Local filter applied: 4 of 4 records matched filter:{ } 16:43:31.999:XRP3:INFO:ResultSet:isc_XDataSource_3:dsResponse for successful operation of type add did not return updated record[s]. Using submitted request data to update ResultSet cache. 16:43:31.999:XRP3:DEBUG:ResultSet:isc_XDataSource_3:Submitted data to be integrated into the cache:[ {codigo: "PRUEBA", nombre: "Prueba"} ] 16:43:32.004:RDQ5:DEBUG:ResultSet:isc_ResultSet_1 (created by: isc_ListGrid_1):getRange(0, 3) satisfied from cache

Sorry I forgot to say it happens the same in insert, this is the insert log:

13:22:09.162:KPR3:DEBUG:gridEdit:isc_ListGrid_0:change detection: newValues: {codigo: "prueba",
nombre: "prueba"}, oldValues: undef
13:22:09.167:KPR3:DEBUG:gridEdit:isc_ListGrid_0:At field: codigo applying validators: [
{type: "isString",
typeCastValidator: true,
_generated: true,
defaultErrorMessage: "Debe ser una Cadena."},
{type: "required",
defaultErrorMessage: undef,
errorMessage: "Campo es obligatorio"}
] to value:prueba
13:22:09.168:KPR3:INFO:gridEdit:isc_ListGrid_0:validateFieldValue, newValue: "prueba", passed validation: true, resultingValue: null
13:22:09.170:KPR3:DEBUG:gridEdit:isc_ListGrid_0:At field: nombre applying validators: [
{type: "isString",
typeCastValidator: true,
_generated: true,
defaultErrorMessage: "Debe ser una Cadena."},
{type: "required",
defaultErrorMessage: undef,
errorMessage: "Campo es obligatorio"}
] to value:prueba
13:22:09.172:KPR3:INFO:gridEdit:isc_ListGrid_0:validateFieldValue, newValue: "prueba", passed validation: true, resultingValue: null
13:22:09.172:KPR3:INFO:gridEdit:isc_ListGrid_0:Saving newValues '{codigo: "prueba",
nombre: "prueba"}'
13:22:10.612:XRP7:DEBUG:ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):dataSource data changed firing
13:22:10.612:XRP7:INFO:ResultSet:isc_XDataSource_1:dsResponse for successful operation of type add did not return updated record[s]. Using submitted request data to update ResultSet cache.
13:22:10.612:XRP7:DEBUG:ResultSet:isc_XDataSource_1:Submitted data to be integrated into the cache:[
{codigo: "prueba",
nombre: "prueba"}
]
13:22:10.613:XRP7:INFO:ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):updating cache in place after operationType: add, allMatchingRowsCached true
13:22:10.613:XRP7:INFO:ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):Updating cache: operationType 'add' submitted by 'isc_ListGrid_0',1 rows update data:
[
{codigo: "prueba",
nombre: "prueba"}
]
13:22:10.614:XRP7:INFO:ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):Local filter applied: 3 of 3 records matched filter:{
}
13:22:10.615:XRP7:INFO:ResultSet:isc_XDataSource_1:dsResponse for successful operation of type add did not return updated record[s]. Using submitted request data to update ResultSet cache.
13:22:10.615:XRP7:DEBUG:ResultSet:isc_XDataSource_1:Submitted data to be integrated into the cache:[
{codigo: "prueba",
nombre: "prueba"}
]
13:22:10.627:RDQ9:DEBUG:ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):getRange(0, 2) satisfied from cache

This is what send my server JSON as response to add new register:

input: {
    "__requestBody": {
        "dataSource": "isc_XDataSource_1",
        "operationType": "add",
        "data": {
            "nombre": "prueba",
            "codigo": "prueba"
        },
        "componentId": "isc_ListGrid_0",
        "oldValues": null
    },
    "inputfields": [
        {
            "value": "prueba",
            "property": "nombre"
        },
        {
            "value": "prueba",
            "property": "codigo"
        }
    ],
    "__requestFormat": "smartgwt",
    "__httpSession": "org.apache.catalina.session.StandardSessionFacade@1c2b15c",
    "__http_request": "org.apache.catalina.connector.RequestFacade@18d70a6",
    "fields": [
        {
            "name": "id",
            "property": "id"
        },
        {
            "name": "codigo",
            "property": "codigo"
        },
        {
            "name": "nombre",
            "property": "nombre"
        }
    ]
}

And this is my response of update register:

{
    "id": "1",
    "__requestBody": {
        "dataSource": "isc_XDataSource_2",
        "operationType": "update",
        "data": {
            "nombre": "prueba2",
            "id": "1"
        },
        "componentId": "isc_ListGrid_0",
        "oldValues": {
            "id": "1",
            "codigo": "prueba",
            "nombre": "prueba"
        }
    },
    "inputfields": [
        {
            "value": "prueba2",
            "property": "nombre"
        },
        {
            "value": "1",
            "property": "id"
        }
    ],
    "__requestFormat": "smartgwt",
    "__httpSession": "org.apache.catalina.session.StandardSessionFacade@1c2b15c",
    "__http_request": "org.apache.catalina.connector.RequestFacade@1d40d08",
    "fields": [
        {
            "name": "id",
            "property": "id"
        },
        {
            "name": "codigo",
            "property": "codigo"
        },
        {
            "name": "nombre",
            "property": "nombre"
        }
    ]
}
2
It would be good to see what your response from the server looks like. Could you please update your post with that info? SmartGWT will not create any ids for you, you will have to provide them yourself. Side-note: If your response is JSON-formatted, you also need to set the DataFormat of the datasource to JSON. - Mia Clarke
Ok, I updated with my json server-send. - user670852

2 Answers

0
votes

You can't change the primary key with an update (just as in SQL). Do a remove, then an add.

0
votes

The logs are telling you exactly what's wrong:

16:43:31.999:XRP3:INFO:ResultSet:isc_XDataSource_3:dsResponse for successful operation of type add did not return updated record[s]. Using submitted request data to update ResultSet cache.

Your JSON response is just random data basically, SmartGWT doesn't know what to do with it because you haven't declared anything about it's format or meaning. So SmartGWT just uses the submitted data as update data, and the submitted data obviously doesn't contain the new id value you generated on the server.

Start with the QuickStart Guide, Data Integration chapter and follow all the links to further reference. In a nutshell, your DataSource declaration tells SmartGWT how to process your responses. There are recommended formats you can just use (RestDataSource) or you can declare properties such as recordXPath to have SmartGWT parse your existing format.