0

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:

  1. User click
  2. The dialog with loading process is showed
  3. The bean loads the data
  4. Complete the generation of the PDF
  5. The dialog is dismissed
  6. The printable document is shoed in a new tab

How Can I achieve this?

I love coding
  • 1,183
  • 3
  • 18
  • 47
  • 1
    https://stackoverflow.com/questions/51946617/how-to-display-pdf-on-jsf or https://stackoverflow.com/questions/13931999/send-a-pdf-to-browser-via-jsf or https://stackoverflow.com/questions/13533339/print-pdf-report-directly-instead-of-downloading-opening-and-printing-it/38010496#38010496 – Kukeltje Nov 07 '19 at 16:44
  • Most of the link mentioned and searched by me was not working. The trick was the usage of the target="_blank", but this trick is not working well with commandButton. How Can I achieve what wanted in the update? @Kukeltje – I love coding Nov 07 '19 at 20:20
  • And what is the behaviour then without the target? (It works for others without this), again see the upvotes on my comments. And your update is a new question, Please remove the update and create a new question and answer the original question with references to the links I posted and EXPLICIT INFO on why it was not sufficient. That is how stackoverflow works. – Kukeltje Nov 07 '19 at 20:52
  • And remarkable that you **don't** use content-disposition, since that is what solves your original problem.. – Kukeltje Nov 07 '19 at 20:54
  • @Kukeltje I've changed the question, I hope it will be easier to understand what I want. – I love coding Nov 08 '19 at 12:17

0 Answers0