I'am facing a little problem using p:fileDownload inside p:datalist : download button doesn't process my action when it is in datalist but works fine outside.
Here is my .xhtml :
Code: Select all
<h:form>
<p:commandButton value="Download !" ajax="false">
<!-- This one works fine -->
<p:fileDownload value="#{cdcView.pdfFile}" />
</p:commandButton>
<p:dataList value="#{cdcView.documents}" var="document" itemType="none">
<p:commandButton value="Download" ajax="false">
<!-- This one just submit form -->
<p:fileDownload value="#{cdcView.pdfFile}" />
</p:commandButton>
</p:dataList>
</h:form>
Code: Select all
@ManagedBean
@ViewScoped
public class CdcView {
private List<Document> documents;
private StreamedContent pdfFile;
@EJB
private DocumentFacade documentFacade;
public List<Document> getDocuments() {
if (documents == null) {
documents = documentFacade.findAll();
}
return documents;
}
public StreamedContent getPdfFile() {
//Just for testing
InputStream stream = new ByteArrayInputStream(getDocuments().get(0).getContent());
pdfFile = new DefaultStreamedContent(stream, "application/pdf", "documents.pdf");
return pdfFile;
}
}
I also tried with p:commandlink, h:commandButton and p:commandLink without success.
I can't figure why it is working as expected outside the datalist ?
I am using PrimeFaces 2.1 / JSF 2.0.3 / GlassFish 3
Thanks for help