Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    JSON RestDataSource once transaction - multiple "add" operation returning data record

    Hi, with SmartGwt 5, I can't find the correct JSON format return need by my ListGrid and her RestDataSource (only in case of multiple "add" in same operation/transaction).

    The doc, explain a bad return, but I search one JSON correct response...

    Previously i use correctly a XML datasource, but i didn't find the equivalent with JSON.

    With XML correctly working, the result need to be :
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <responses>
    	<response>
    		<data>
    			<record>
    ...
    			</record>
    		</data>
    	</response>
    	<response>
    		<data>
    			<record>
    ...
    			</record>
    		</data>
    	</response>
    	<status>0</status>
    </responses>
    But, with JSON, after differents tests, is not working something like :
    Code:
    {
    	"responses": {
    		"status": 0,
    		"response": [{
    			"response": {
    				"status": 0,
    				"data": {
    ...
    				}
    			}
    		},
    		{
    			"response": {
    				"status": 0,
    				"data": {
    ...
    				}
    			}
    		}]
    	}
    }
    It's a classic RestDataSource JSON.
    Code:
    RestDataSource dataSource = new RestDataSource();
    dataSource.setDataFormat(DSDataFormat.JSON);
    dataSource.setDataProtocol(DSProtocol.POSTMESSAGE);
    
    OperationBinding add = new OperationBinding();
    add.setOperationType(DSOperationType.ADD);
    add.setDataProtocol(DSProtocol.POSTMESSAGE);
    Can you give me and to the documentation a working sample of JSON response with two operations in same transaction ?

    For example, the client call :
    Code:
    {
    	"transaction": {
    		"transactionNum": 52,
    		"operations": [{
    			"dataSource": "isc_sector_5_0",
    			"operationType": "add",
    			"textMatchStyle": "exact",
    			"componentId": "UPStockOT58",
    			"data": {
    				"id": 1244962,
    				"_selection_27": true
    			},
    			"oldValues": null
    		},
    		{
    			"dataSource": "isc_sector_5_0",
    			"operationType": "add",
    			"textMatchStyle": "exact",
    			"componentId": "UPStockOT58",
    			"data": {
    				"id": 1328573,
    				"_selection_27": true
    			},
    			"oldValues": null
    		}]
    	}
    }

    Edit and SOLVED (reading this SmartGwt post):

    The reply must be :
    Code:
    [{
    	"response": {
    		"status": 0,
    		"data": {
    ...
    		}
    	}
    },
    {
    	"response": {
    		"status": 0,
    		"data": {
    ...
    		}
    	}
    }]
    but you need use :
    Code:
    dataSource.setJsonPrefix("");
    dataSource.setJsonSuffix("");
    or configure servlet JSON return by adding default json*fix used by client.
    Last edited by immobilia; 30 Dec 2014, 02:14. Reason: SOLVED
Working...
X