Using p:fileDownload in p:dataList

UI Components for JSF
Post Reply
vlenair
Posts: 4
Joined: 10 Aug 2010, 09:59

24 Aug 2010, 11:03

Hi,

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>
And my bean :

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;
	}
}
Document is just a POJO with a "content" field which is a byte array

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 ;)

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

24 Aug 2010, 15:18

You need a p:column to process selections;

Code: Select all

<p:dataList value="#{cdcView.documents}" var="document" itemType="none">  
<p:column>
      <p:commandButton value="Download" ajax="false">
         <!-- This one just submit form -->
         <p:fileDownload value="#{cdcView.pdfFile}" />
      </p:commandButton>
</p:column>
   </p:dataList>

vlenair
Posts: 4
Joined: 10 Aug 2010, 09:59

25 Aug 2010, 07:31

Yep, that's it !

Tank you for help, next time i'll read the whole documentation :?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

25 Aug 2010, 10:52

Yes, page 106 mentions that you need a p:column to process selections ;)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 46 guests