p:fileDownload Problem with several Pdf-Links

UI Components for JSF
Post Reply
mario_
Posts: 36
Joined: 17 Feb 2011, 12:49

28 Feb 2011, 23:43

Hi,

I'm using PrimeFaces-2.2.1 on Mojarra-2.0.4.

Following Problem:

Defining a site with two links to download pdf files:

Code: Select all

	<h:form>
	<h:commandLink ajax="false">
		<h:outputText value="Pdf 1" />
		<p:fileDownload value="#{testBean.getPdf('Pdf 1')}" />		
	</h:commandLink>
	<h:commandLink ajax="false">
		<h:outputText value="Pdf 2" />
		<p:fileDownload value="#{testBean.getPdf('Pdf 2')}" />				
	</h:commandLink>
	</h:form>

And the method for the pdf:

Code: Select all

	public StreamedContent getPdf(String value) throws IOException, DocumentException {
		Document document = new Document(PageSize.A4);
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		PdfWriter.getInstance(document, out);
		document.open();
		document.add(new Phrase(value));
		document.close();
		
		return new DefaultStreamedContent(new ByteArrayInputStream(out.toByteArray()), 
				"application/pdf", 
				"Doc-"+ value + ".pdf");
	}
When I click the first time on one of the links, every think is fine. But once you click the first link, the second link will show the same Pdf.

I think because the site is not refreshed and the hidden input field (for the parameters) is still in the site. So this will post too to the server.

mario_
Posts: 36
Joined: 17 Feb 2011, 12:49

30 Mar 2011, 13:54

The Problem comes with the Tag h:commandLink. Since the lastest version of Mojarra, the Prolbem is solved. But using p:commandLink instead of h:commandLink comes to the old problem:

Code: Select all

   <h:form>
   <p:commandLink ajax="false">
      <h:outputText value="Pdf 1" />
      <p:fileDownload value="#{testBean.getPdf('Pdf 1')}" />      
   </p:commandLink>
   <p:commandLink ajax="false">
      <h:outputText value="Pdf 2" />
      <p:fileDownload value="#{testBean.getPdf('Pdf 2')}" />            
   </p:commandLink>
   </h:form>

Code: Select all

public StreamedContent getPdf(String value) throws IOException, DocumentException {
      Document document = new Document(PageSize.A4);
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      PdfWriter.getInstance(document, out);
      document.open();
      document.add(new Phrase(value));
      document.close();
      
      return new DefaultStreamedContent(new ByteArrayInputStream(out.toByteArray()),
            "application/pdf",
            "Doc-"+ value + ".pdf");
   }
Since I can use h:commandLink, bugfixing of p:commandLink isn't ugent any more

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 21 guests