I need to export RestDataSource data as an XLS attachment.
Please note we are just evaluating to buy SmartGWT Pro or better license for Excel export and other useful features (and we are also aware of "client-driven export") but not for the current project.
I'm using SmartClient Version: SC_SNAPSHOT-2011-12-05/LGPL Development Only (built 2011-12-05)
So I actually need to export a file based on the same data that the datasource serves to the ListGrid instance. The request should simply bring a different mime type param and additional metadata just to switch behavior: it usually produces JSON, this time it should produce an attachment.
Since my datasource does some parameters elaboration (overriding transformRequest ()) and the server is aware of that parameters structure, I've managed to forge the request reusing my DataSource logic and sending it via RPCManager.sendRequest (). It sends correct data to the server, and the server responds with the attachment, but the client don't show a save dialog.
This is the relevant code
What's wrong with my code?
Is there a better to achieve this behavior or a similar one (that re-uses the original datasource request preparation logic)?
Please note we are just evaluating to buy SmartGWT Pro or better license for Excel export and other useful features (and we are also aware of "client-driven export") but not for the current project.
I'm using SmartClient Version: SC_SNAPSHOT-2011-12-05/LGPL Development Only (built 2011-12-05)
So I actually need to export a file based on the same data that the datasource serves to the ListGrid instance. The request should simply bring a different mime type param and additional metadata just to switch behavior: it usually produces JSON, this time it should produce an attachment.
Since my datasource does some parameters elaboration (overriding transformRequest ()) and the server is aware of that parameters structure, I've managed to forge the request reusing my DataSource logic and sending it via RPCManager.sendRequest (). It sends correct data to the server, and the server responds with the attachment, but the client don't show a save dialog.
This is the relevant code
Code:
final DSRequest dsr = new DSRequest(); dsr.setActionURL(actionURL); dsr.setDownloadResult(true); dsr.setDownloadToNewWindow(true); dsr.setOperationType(DSOperationType.ADD); dsr.setHttpMethod("POST"); dsr.setUseSimpleHttp(true); dsr.setContentType("application/json"); dsr.setTransport(RPCTransport.XMLHTTPREQUEST); dsr.setExportResults(true); final Map<String, String> httpHeaders = new HashMap<String, String>(); httpHeaders.put("Accept", "application/vnd.ms-excel"); dsr.setHttpHeaders(httpHeaders); ... dsr.setData(payload); RPCManager.sendRequest(dsr);
Is there a better to achieve this behavior or a similar one (that re-uses the original datasource request preparation logic)?
Comment