Hi All,

I'm using the classic Tomcat/BlazeDS - Flex environment.

What I'm doing is exporting a DataGrid and AdvancedDatagrid to Excel files. I generate a matching excel file on the server and download it using specific servlets.

The thing I want to do is generate the same file on the server and return a path which can be recognized by a URLRequest to be used by the FileReference.

Basically it would go like this:

<mx:RemoteObject destination="ExcelExportService" id="ExcelExportService" showBusyCursor="true" fault="excelFaultHandler(event)" result="excelFileNameHandler(event)">
    </mx:RemoteObject>

            private function exportToExcel():void {
ExcelExportService.getExcelFileName(statParams); // some params i use on the server side
            }

            private function excelFaultHandler(event:FaultEvent):void {
                trace("Excel creation failed !");
            }

public function excelFileNameHandler(event:ResultEvent):void {
                exportFilename = event.result as String;
if (exportFilename == null || exportFilename.length == 0) {
                    trace("Empty or non existent file !");
                } else {
                    downloadExcelFile(exportFilename);
                }
            }

private function downloadExcelFile(fileToDownload:String):void { var fileName:String = UrlUtils.getAppBaseUrl() + "/" + fileToDownload;

                var urlReq:URLRequest = new URLRequest(fileName);
var templateFileRef:FileReference = new FileReference();
                // Lots of event listeners omitted
                templateFileRef.download(urlReq);
            }

<mx:HBox horizontalAlign="right" width="100%">
    <!-- mx:Label id="testLabel" text="Test Label"/-->
<mx:Button id="excelButton" label="Export to excel" click="exportToExcel()" icon="{AssetManager.btnExcel}"/>
</mx:HBox>



Has anybody any idea on how to do it ?

        Thanks in advance

Farid


Reply via email to