I've implemented a mechanism to generate and download a PDF within my JSF page, with the usage a method within my bean. Here are the component to perform this operation:
<p:commandButton title="Stampa" icon="ui-icon-print"
ajax="false" onclick="PrimeFaces.monitorDownload(start, stop);"
rendered="#{productionOrdersView.showMenuOptions()}"
target="_blank"
actionListener="#{productionOrdersView.print(true)}">
</p:commandButton>
And this is the method in the bean:
public StreamedContent generateSelectedPDFFile() {
String fileName = "Bolla_" + selected.getOrderNumber();
InputStream stream = new ByteArrayInputStream(
new GenerateStatusPDF(companyInfo).generate(selected).toByteArray());
StreamedContent file = new DefaultStreamedContent(stream, "application/pdf", fileName + ".pdf");
return file;
}
I want to achieve this pattern:
- User click
- The dialog with loading process is showed
- The bean loads the data
- Complete the generation of the PDF
- The dialog is dismissed
- The printable document is shoed in a new tab
How Can I achieve this?