Hi,
Have any of you been able to add a Record to a RestDataSource with dataFormat JSON ?
The following code give an error:
The stacktrace in the Developer Consoel is:
14:40:36.883:MUP2:WARN:Log:Error:
'Object doesn't support this property or method'
in http://localhost/X/sc/modules/ISC_Core.js
at line 3467
JSONEncoder.$zo(_1=>com.smartgwt.client.data.Record@ada9d2, _2=>".dataSource.operationType.data.__ref", _3=>Obj, _4=>" ")
JSONEncoder.$eu(_1=>com.smartgwt.client.data.Record@ada9d2, _2=>" ", _3=>".dataSource.operationType.data.__ref")
** recursed on JSONEncoder.$zo
No data has been sent to the server.
Have any of you been able to add a Record to a RestDataSource with dataFormat JSON ?
The following code give an error:
Code:
final Record newRecord = new Record(); newRecord.setAttribute(XDataSource.FIELD_A, "a"); newRecord.setAttribute(XDataSource.FIELD_A, "b"); newRecord.setAttribute(XDataSource.FIELD_CREATED_AT, new Date()); xDataSource.addData(newRecord, new DSCallback() { @Override public void execute(DSResponse dsResponse, Object o, DSRequest dsRequest) { if (dsResponse != null && dsResponse.getData() != null && dsResponse.getData().length == 1) { eventBus.fireEvent(new XWindowEvent(dsResponse.getData()[0], XWindowEvent.Kind.OPEN)); } else { SC.say(messageConstants.errorCommunicatingWithServer()); } } });
14:40:36.883:MUP2:WARN:Log:Error:
'Object doesn't support this property or method'
in http://localhost/X/sc/modules/ISC_Core.js
at line 3467
JSONEncoder.$zo(_1=>com.smartgwt.client.data.Record@ada9d2, _2=>".dataSource.operationType.data.__ref", _3=>Obj, _4=>" ")
JSONEncoder.$eu(_1=>com.smartgwt.client.data.Record@ada9d2, _2=>" ", _3=>".dataSource.operationType.data.__ref")
** recursed on JSONEncoder.$zo
No data has been sent to the server.
Code:
public class XDataSource extends RestDataSource { public static String FIELD_A = "A"; public static String FIELD_B = "B"; public static String FIELD_CREATED_AT = "createdAt"; public static String serviceUrl = "http://localhost/X/x"; public XDataSource(String id) { setID(id); setDataFormat(DSDataFormat.JSON); setJsonRecordXPath("/"); setDropExtraFields(true); setSendExtraFields(true); DataSourceIntegerField pkField = new DataSourceIntegerField("id"); // unitId pkField.setRequired(false); pkField.setHidden(true); pkField.setPrimaryKey(true); FieldValueExtractor valueExtractor = new FieldValueExtractor() { @Override public Object execute(Object record, Object value, DataSourceField field, String fieldName) { if (value instanceof String) { return isoDateFormat.format(isoDateFormat.parse((String) value)); } else return null; } }; DataSourceDateField createdAtField = new DataSourceDateField(FIELD_CREATED_AT); createdAtField.setFieldValueExtractor(valueExtractor); DataSourceIntegerField aField = new DataSourceIntegerField(FIELD_A); DataSourceIntegerField bField = new DataSourceIntegerField(FIELD_B); setFields(pkField, aField, bField, createdAtField); setDataURL(serviceUrl); OperationBinding fetch = new OperationBinding(DSOperationType.FETCH, serviceUrl); fetch.setDataProtocol(DSProtocol.GETPARAMS); OperationBinding add = new OperationBinding(DSOperationType.ADD, serviceUrl); add.setDataProtocol(DSProtocol.POSTMESSAGE); OperationBinding update = new OperationBinding(DSOperationType.UPDATE, serviceUrl); update.setDataProtocol(DSProtocol.POSTMESSAGE); OperationBinding remove = new OperationBinding(DSOperationType.REMOVE, serviceUrl); remove.setDataProtocol(DSProtocol.POSTMESSAGE); setOperationBindings(fetch, update, remove, add); } @Override public Object transformRequest(DSRequest dsRequest) { dsRequest.setContentType("application/json; charset=utf-8"); return super.transformRequest(dsRequest); } @Override public void transformResponse(DSResponse dsResponse, DSRequest dsRequest, Object object) { super.transformResponse(dsResponse, dsRequest, object); } }
Comment