Hello,
I'm trying to download a PDF in my application but I can not.
When I click the Download button instead of downloading, you are checking in form if the required fields have been filled in.
If you fill in all the fields it works normally.
Below is the code:
<h:form id="formTeste" >
<p:panel toggleable="true" id="pgFormTeste" header="Teste">
<h:panelGrid columns="2">
<p:outputLabel for="descricao" value="Descrição:" />
<p:inputText value="#{testeController.teste.desc}" required="true" />
<p:outputLabel value= "PDF:" />
<p:commandButton value="Download" ajax="false">
<p:fileDownload value="#{testeController.getFile()}" />
</p:commandButton>
</h:panelGrid>
</p:panel>
</form>
Controller:
private String pathPDF = System.getProperty("jboss.apps.data.dir") + File.separator + "sigeap" + File.separator + "001.pdf";
public void setFile(StreamedContent file) {
this.file = file;
}
public StreamedContent getFile() throws FileNotFoundException {
FileInputStream stream = new FileInputStream(pathPDF);
file = new DefaultStreamedContent(stream, "application/pdf", "001.pdf");
return file;
}
If I did that, it would solve a lot of my problem ...
Taking advantage of this, if anyone also knows how I can open the PDF that is in a folder on the server directly in the browser as it does PDFObject would help a lot as well.
Thank you