Im currently looking for a solution to invoke a pagenavigation from "foo.xhtml" to "bar.xhtml" and starting a download dialogue at the same time. I already implemented a solution which worked on my test tomcat, but the JavaScript got cut out on the targetplatform, a WAS 8.0.0.9.
<c:if test="#{Bean.downloadPreconditions()}"> <!-- checks a simple boolean variable which gets set to 'true' after all informations for the download are set-->
<script>
window.onload = function() {
document.getElementById('form:download').onclick();
}
</script>
<h:commandLink id="download"
action="PrimeFaces.monitorDownload(start, stop);">
<p:fileDownload value="#{Bean.downloadFile}"></p:fileDownload>
</h:commandLink>
In this solution i start the download via JavaScript AFTER i redirected to the targetpage "bar.xhtml" from "foo.xhtml".
The PreRenderView solution does not work, because i visited the view before and it does not get freshly instantiated.
I tried several slightly different PrimeFaces.monitorDownload(start, stop);
version with an attached <p:fileDownload>
, as well as a download invoked by a backingbean like it is described here.
I am aware that im trying to call 2 requests to the server with one single click. I want to know if it is still somehow possible to maybe first switch to the target view and after that call the download dialogue in an automated way.