Primefaces commandButton download complete hide dialog
In PrimeFaces 5.1 p:commandButton press to call download action. In action to get data from DB and create pdf. When its complete to download the pdf. My problem huge data create to taken a time that time I want to show dialog box, because user that time no for further action to done. CommandButton press I show dialog but can't know how to close dialog box.If any other way to complete action to close dialog.
stud.xhtml
<p:commandButton value="download" action="#{stud.downloadAction}" onclick="PF('progressWaitDialog').show()" ajax="false" onComplete="PF('progressWaitDialog').hide();"/>
<p:dialog id="progressWaitDialog" widgetVar="progressWaitDialog" modal="true">
<h:graphicImage value="#{stud.progressWaitBar}"/>
</p:dialog>
stud.java
public string downloadAction()
{
createPdf(studenToList);
return null;
}
My doubt commanButton click open dialog but download action complete how to hide dialog?
If you are using PrimeFaces, you can take advantage of PrimeFaces.monitorDownload and <p:fileDownload> . It is documented here.
Basically, you have to change your commandButton to use an actionListener instead an action . This actionListener prepares an org.primefaces.model.StreamedContent to stream the file you want to download. This stream has to be wired with value attribute of <p:fileDownload> .
To prepare that StreamedContent , if your createPdf(studenToList) method returns a file, it would be as easy as following:
String mime = "application/pdf";
String name = "your-file-name.pdf";
File file = createPdf(studenToList);
StreamedContent stream = new DefaultStreamedContent(file, mime, name);
The onclick event of your commandButton will call the monitorDownload javascript of PrimeFaces onclick="PrimeFaces.monitorDownload(startFaDwn, stopFaDwn);" .
Finally, you have to provide your own implementation of startFaDown and stopFaDown . This is mine:
<script type="text/javascript">
function startFaDwn() {
PF('FADownloadDlg').show();
}
function stopFaDwn() {
PF('FADownloadDlg').hide();
}
</script>
As you can see, both functions open and hide a dialog as you want. You can name these functions as you want, and obviously it can do what you want, not only open/close dialog.
You won't need onComplete event, neither ajax="false" attribute.
Hope it helps!
链接地址: http://www.djcxy.com/p/68558.html上一篇: Android 4.4不采摘背景图片
