Download - not export table - files from portal-portlet

I see that Designer has controls to export a table to a .csv file, and to upload a file from a user’s desk.
I need to write a portlet that allows external users to select and download files of different formats (.xls, .pdf, .doc, …).
Has anyone written download functionality for a portlet?

I just had to do this yesterday. I used streamFileDataToResponse(FileContentExportBean). Here is the relevant code:

File f = new File(“HelloMe.pdf”);
boolean forceDownload = true;
FileContentExportBean eb = new FileContentExportBean(f, forceDownload);
streamFileDataToResponse(eb);

Hope it helps.

Thanks for the info. I tried it but was unsuccessful. “Access denied” is the error I get when I try to use it. Again, I am NOT a Java coder, so it is VERY difficult for me to decipher what/where to insert code, then to debug it.

Hi,
where does the files to be downloaded come from? how do you access them inside your portlet?
Have a look at http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuite8_ga/My_webMethods_and_Task_Engine/8-0-SP1_CAF_and_MWS_Java_API_Reference/com/webmethods/caf/faces/bean/SimpleFileExportBean.html for details on how you can use the SimpleFileExportBean.

Additionally, the button (or icon) you use to trigger the download of the file/s must not be an “async” button. And, you have to add an action listener to that button to re-enable the buttons in the form after the download is finished. You could add this snippet in an Script Block at the end of the page:


Event.observe( window, 'load', function() {
CAF.model('#activePageBean.clientIds['downloadButton']}').addActionListener(function(id) {Form.enableButtons(document.body);});
});

Hope this is clear enough and helps,
Javier

Brilliant. Thanks Javier. (Slightly) corrected syntax:

Event.observe( window, 'load', function() 
{  
	CAF.model('#{activePageBean.clientIds['downloadButton']}').addActionListener(function(id) {Form.enableButtons(document.body);});  
});