Found a problem with JSON data format on RestDatasource

Hi,

I have been playing with smartclient and found that there are some problems when a RestDataSource has its dataFormat defined as “json”. When this happens, the Databound component (tested with grid and tree) will not be able to reflect any newly added or updated records.

I have tested using the isomorphic example found in my own copy of smartclient at
http://localhost:8080/isomorphic/system/reference/SmartClient_Explorer.html#restEditSave and changed the 2 files country_fetch.xml and country_add.xml accordingly.

(in your smatclient website, you can refer to this copy. http://www.smartclient.com/isomorphic/system/reference/SmartClient_Explorer.html#restEditSave).

Whenever I add "dataFormat: “json” into the datasource definition and then replace the xml data with json format. Loading JSON formatted data works without any problems. However clicking on the add button does not refresh the list data with the new entry.

Below are the data I converted from xml to json. Please confirm if this is indeed a problem or have I generate the wrong json format?

Thanks in advance

---------Section modified in the example JS
isc.RestDataSource.create({
ID:“countryDS”,
dataFormat:“json”,
fields:[
{name:“countryCode”, title:“Code”, primaryKey:true, canEdit:“false”},
{name:“countryName”, title:“Country”},
{name:“capital”, title:“Capital”}
],

fetchDataURL:"/isomorphic/system/reference/inlineExamples/dataIntegration/xml/responses/country_fetch_rest.xml",
addDataURL :"/isomorphic/system/reference/inlineExamples/dataIntegration/xml/responses/country_add_rest.xml",
updateDataURL:"/isomorphic/system/reference/inlineExamples/dataIntegration/xml/responses/country_update_rest.xml",
removeDataURL:"/isomorphic/system/reference/inlineExamples/dataIntegration/xml/responses/country_remove_rest.xml"

});

------country_fetch.xml
{
response: {
status: 0,
startRow: 0,
endRow: 7,
totalRows: 7,
data: [
{
continent: “North America”,
countryName: “United States”,
countryCode: “US”,
area: 9631420,
gdp: 1830000,
population: 298444215,
independence: “1776-07-04”,
government: “federal republic”,
government_desc: 2,
capital: “Washington, DC”,
members_g8: true,
article: “http://en.wikipedia.org/wiki/United_states”
},
{
continent: “Europe”,
countryName: “Germany”,
countryCode: “GM”,
area: 357021,
gdp: 1830000,
population: 82422299,
independence: “1871-01-18”,
government: “federal republic”,
government_desc: 2,
capital: “Berlin”,
members_g8: true,
article: “http://en.wikipedia.org/wiki/Germany”
},
{
continent: “Europe”,
countryName: “United Kingdom”,
countryCode: “UK”,
area: 60609153,
population: 298444215,
gdp: 1830000,
independence: “1801-01-01”,
government: “constitutional monarchy”,
government_desc: 2,
capital: “London”,
members_g8: true,
article: “http://en.wikipedia.org/wiki/United_kingdom”
},
{
continent: “Europe”,
countryName: “France”,
countryCode: “FR”,
area: 547030,
population: 298444215,
gdp: 1816000,
government: “republic”,
government_desc: 2,
capital: “Paris”,
members_g8: true,
article: “http://en.wikipedia.org/wiki/France”
},
{
continent: “South America”,
countryName: “Brazil”,
countryCode: “BR”,
area: 8511965,
population: 188078227,
gdp: 1556000,
independence: “1822-09-07”,
government: “federative republic”,
government_desc: 3,
capital: “Washington, DC”,
members_g8: false,
article: “http://en.wikipedia.org/wiki/Brazil”
},
{
continent: “North America”,
countryName: “Canada”,
countryCode: “CA”,
area: 9984670,
population: 33098932,
gdp: 1114000,
independence: “1867-07-01”,
government: “constitutional monarchy with parliamentary democracy and federation”,
government_desc: 1,
capital: “Ottawa”,
members_g8: true,
article: “http://en.wikipedia.org/wiki/Canada”
},
{
continent: “North America”,
countryName: “Mexico”,
countryCode: “MX”,
area: 1972550,
population: 107449525,
gdp: 1067000,
independence: “1810-09-16”,
government: “federal republic”,
government_desc: 2,
capital: “Mexico (Distrito Federal)”,
members_g8: false,
article: “http://en.wikipedia.org/wiki/Mexico”
}
]
}
}

------------------------End Country fetch.xml

-------country_add.xml
{
response: {
status: 0,
data: [
{
countryCode: “A1”,
countryName: “Saved Value”,
capital: “Saved Value”,
continent: “Saved Value”
}
]
}
}
------------------------End country_add.xml

Getting a “works for me” result in 6.0 SmartClient SDK, with the minor difference that I just placed some files in webroot rather than modifying the example as such:

fetchDataURL:"/rest_fetch_response.json",
addDataURL :"/rest_add_response.json",
  1. have you tried clearing your cache?

  2. are you seeing JS errors?

  3. what do you see if you set the RPCManager log to DEBUG level or use the RPCs tab with “Track RPCs” enabled? Do you see the expected JSON format responses?

  4. what do you see if you set the ResultSet log to DEBUG? Normal logs look something like:

07:15:51.318:XRP8:DEBUG:ResultSet:isc_ResultSet_19:dataSource data changed firing
07:15:51.333:XRP8:INFO:ResultSet:isc_ResultSet_19:updating cache in place after operationType: add, allMatchingRowsCached true
07:15:51.333:XRP8:INFO:ResultSet:isc_ResultSet_19:Updating cache: operationType 'add', 1 rows update data:
[
{countryCode: "A1",
countryName: "Saved Value",
capital: "Saved Value",
continent: "Saved Value"}
]
07:15:51.333:XRP8:INFO:ResultSet:isc_ResultSet_19:sortByProperty(countryCode, true): full cache allows local sort
07:15:51.349:XRP8:INFO:ResultSet:isc_ResultSet_19:Local filter applied: 8 of 8 records matched filter:{}
07:15:51.349:XRP8:INFO:ResultSet:isc_ResultSet_19:sortByProperty(countryCode, true): full cache allows local sort
07:15:51.396:RDQ1:DEBUG:ResultSet:isc_ResultSet_19:getRange(0, 7) satisfied from cache
  1. have you tried doing this without modifying example files? It’s a little dubious in terms of content types to place JSON in a .xml file :slight_smile: