I am using SmartGWTPower 2.4 and Firefox 4.0.1, I have to implement to download a file related to a record in a ListGrid.
I set a field type to "binary" but there was no download icon in the ListGrid, so I added an IButton to the Layout.
The download works fine, but there is a problem with the error handling. I used the same error handling in the catch clause as in core DS operations (executeFetch, executeAdd, executeUpdate, executeRemove) and a popup appeared with the error message. In case of executeDownload, the former screen disappeared and the following page appeared:
ds.xml:
client:
server:
server log:
Please help me, to resolve this problem.
I set a field type to "binary" but there was no download icon in the ListGrid, so I added an IButton to the Layout.
The download works fine, but there is a problem with the error handling. I used the same error handling in the catch clause as in core DS operations (executeFetch, executeAdd, executeUpdate, executeRemove) and a popup appeared with the error message. In case of executeDownload, the former screen disappeared and the following page appeared:
Code:
<HTML> <BODY ONLOAD='var results = document.formResults.results.value;parent.isc.Comm.hiddenFrameReply(2,results)'><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><FORM name='formResults'><TEXTAREA readonly name='results'> //isc_RPCResponseStart-->[{queueStatus:-1,isDSResponse:true,invalidateCache:false,status:-1,data:"My Error Message"}]//isc_RPCResponseEnd</TEXTAREA></FORM> </BODY></HTML>
Code:
<DataSource ID="myCustomDS" serverConstructor="my.app.server.ds.MyCustomDataSource"> <fields> <field name="docid" hidden="true" primaryKey="true" type="text"/> <field name="filename" type="text"/> <field name="fileData" type="binary"/>
Code:
downloadButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { DSRequest requestProperties = new DSRequest(); String filename = myListGrid.getSelectedRecord().getAttributeAsString("filename"); requestProperties.setOperationId(filename); myCustomDS.downloadFile(myListGrid.getSelectedRecord(), "fileData", requestProperties); } });
Code:
public DSResponse executeDownload(DSRequest req) throws Exception { String attachedFile = req.getDownloadFieldName(); String attachedFileName = req.getOperationId(); DSResponse resp = new DSResponse(); resp.setDropExtraFields(true); try { ... req.setDownloadFileName(attachedFileName); Map responseMap = new HashMap(); responseMap.put(attachedFile + "_filename", attachedFileName); responseMap.put(attachedFile + "_filesize", fileData.length); responseMap.put(attachedFile, new ByteArrayInputStream(fileData)); resp.setData(responseMap); resp.setDataSource(req.getDataSource()); } catch (Exception e) { req.setDownloadFieldName(null); resp = new DSResponse("My error message", DSResponse.STATUS_FAILURE); } return resp; }
Code:
INFO: === INFO 2011.06.24 14:36:10 (Logger.java:388) - URL: '/MyProject/myproject/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': Moz (Gecko) with Accept-Encoding header INFO: === DEBUG 2011.06.24 14:36:10 (Logger.java:406) - Parsed XML from (in memory stream): 2ms INFO: === DEBUG 2011.06.24 14:36:10 (Logger.java:406) - Processing 1 requests. INFO: === DEBUG 2011.06.24 14:36:10 (Logger.java:406) - Request #1 (DSRequest) payload: { criteria:{ docid:"12345", download_fieldname:"fileData" }, operationConfig:{ dataSource:"myCustomDS", operationType:"downloadFile" }, appID:"builtinApplication", operation:"mydoc.pdf", oldValues:{ docid:"12345", download_fieldname:"fileData" } } INFO: === INFO 2011.06.24 14:36:10 (Logger.java:388) - Performing 1 operation(s) INFO: === DEBUG 2011.06.24 14:36:10 (Logger.java:406) - [builtinApplication.mydoc.pdf] No userTypes defined, allowing anyone access to all operations for this application INFO: === DEBUG 2011.06.24 14:36:10 (Logger.java:406) - [builtinApplication.mydoc.pdf] No public zero-argument method named '_mydoc.pdf' found, performing generic datasource operation INFO: === DEBUG 2011.06.24 14:36:10 (Logger.java:406) - Content type for RPC transaction: text/html; charset=UTF-8 INFO: === DEBUG 2011.06.24 14:36:10 (Logger.java:406) - non-DMI response, dropExtraFields: true INFO: === INFO 2011.06.24 14:36:10 (Logger.java:388) - /MyProject/myproject/sc/IDACall: 417 -> 266 bytes
Comment