Announcement
Collapse
No announcement yet.
X
-
Originally posted by asg2007It looks like in 2.4 we lost this ability to get custom attributes this way.
Code:@Override protected void transformResponse (DSResponse response, DSRequest request, Object data) { super.transformResponse (response, request, data); JavaScriptObject resp = JSOHelper.getAttributeAsJavaScriptObject ((JavaScriptObject)data, "response"); String mycustomattr = JSOHelper.getAttribute (resp, "mycustomattr"); ... }
Cheers
Davide
Leave a comment:
-
On the server, I just use DSResponse.setAttribute(key,value). As long as there is not name conflict, this seems good enough.
The other suggestion is to add it as extra fields to a record, which is fine if your response will always contain data. Then you use Record.setAttribute(key,value).
Leave a comment:
-
It looks like in 2.4 we lost this ability to get custom attributes this way.
I used the code : if (JSOHelper.isJSO(data)){
JavaScriptObject rawResponse = (JavaScriptObject)data;
Map rawResponseMap = JSOHelper.convertToMap(rawResponse);
Map rawResponseAttributesAsMap = JSOHelper.convertToMap( ((JavaScriptObject)rawResponseMap.get("response")) );
}
but now I can not see my custom attributes in rawResponseAttributesAsMap.
That's pitty.
Leave a comment:
-
Code:protected void transformResponse(DSResponse response, DSRequest request, Object data) { super.transformResponse(response, request, data); JavaScriptObject resp = JSOHelper.getAttributeAsJavaScriptObject((JavaScriptObject) data, "response"); String tl_page = JSOHelper.getAttribute((JavaScriptObject) resp, "tl_page"); }
The attributes does not even have to come under "response" attribute, it could come directly at the same level as the "response" tag. Or there should be maybe a "customResponse" attribute that would be available from DSResponse which would give a map of values found in "{response:{....},customResponse{custom attributes here}}" so one would not mix already existing smartgwt tags in the response tag.
Are there performance concerns or something?
Leave a comment:
-
The answer is in DataSource.transformResponse(DSResponse response, DSRequest request, Object data) and in the Object data in particular. This very "data" in a JSON case is a JavaScriptObject and you can get any custom attribute from it using JSOHelper class and put it manually in "response"Last edited by asg2007; 28 Nov 2010, 06:44.
Leave a comment:
-
Custom attributes in DSResponse. Is it possible?
Hi, could anybody help me with the following?
I am trying to insert my custom attributes (tl_page, etc.) into DSResponse object like that
{
"response":{
"status":0,
"startRow":0,
"endRow":49,
"totalRows":50,
"tl_page":1,
"tl_totalRows":500,
"tl_totalPages":50,
"data":[... etc.
but in the DSCallback in the "execute" method the list of attributes (DSResponse.getAttributes()) does not contain these my attributes. Is there any way to get these attributes from DSResponse? Or maybe from "rawData"?
Thank you.Tags: None
Leave a comment: