This post is about using af:fileDownloadActionListener to generate the file on run-time, exporting viewobject data, suppose I have a view object and I want to export it’s data in CSV or plain text so for this requirement we can generate the file at run-time and send it to client UI to download
What is af:fileDownloadActionListener-
as per oracle docs-
The fileDownloadActionListener tag is a declarative way to allow an action source (<commandButton>, <commandLink>, etc.) to programmatically send the contents of a file to the user, optionally with a specific content type and filename. Since file downloads must be processed with an ordinary request – not XMLHttp AJAX requests – this tag forces partialSubmit to be false on the parent component if it supports that attribute.
The fileDownloadActionListener uses the native (browser built-in) filedownload popup, so this popup cannot be configured.
In this post, I am using Departments table of HR schema
- Prepare model part using Departments table and drop it on the page as a table and add a button to UI for downloading
- drop af:fileDownloadActionListener as child of button and set it’s property as contentType, method , fileName
- Now see code written in download Listener-
- Run this application and click on download button, browser download box appears, open downloaded file and see how your data appears in the text file, to export data in a pdf file you have to generate PDF file using some API then you can download it in the same way
Cheers:) Happy Learning
An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF