I would like to build a results page for a report export page. This results page must display the status of the export and offer the download of this export.
The export is done in an action method. I can execute it via a commandButton but it must be executed automatically on load.
How can I accomplish this?
JSF:
<h:commandButton value="Download report" action="#{resultsView.downloadReport}"/>
Backing bean:
public String downloadReport() {
...
FileDownloadUtil.downloadContent(tmpReport, REPORT_FILENAME);
// Stay on this page
return null;
}
Clarification: Is this feasible with a4j? I thought of a solution that an Ajax request triggers my downloadReport action and its request is the file download.
You can also solve this in JSF 2.0 using component system events, specifically the PreRenderViewEvent.
Just create a download view (/download.xhtml) that fires a download listener before render.
Then, in your report bean (defined using JSR-299), you push the file and mark the response as complete.
That’s all there is to it!
You can either link to the download page (/download.jsf), or use a HTML meta tag to redirect to it on a splash page.