0
Hello,
I’m trying to download a PDF in my application but I’m not getting it.
When I click on the Download instead of downloading is checking in the form if the required fields have been filled in.
Filling in all fields works normally.
Follow the code below:
<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 can do that, it’ll solve most of my problem...
Taking advantage, if someone also knows how to open the PDF that is in a folder on the server directly in the browser as does the Pdfobject would help a lot too.
Thank you
Try
<p:commandButton value="Download" ajax="false" immediate="true">
– Jorge Campos
Thank you very much... It worked perfectly.
– Mamga