JSF 2, Primefaces 2.2.RC2 and file download events

UI Components for JSF
samalairbien
Posts: 4
Joined: 24 Nov 2010, 16:57

02 Dec 2010, 11:50

Hello.
I have a problem with the component p:fileDownload.

I have a dataTable wich presents documents that can be downloaded.

page.xhtml :

Code: Select all

<p:dialog header="..." widgetVar="popup">
	<h:form id="dar_ac_popDocs_form" prependId="false" enctype="multipart/form-data">
		
		... file upload to upload a new document ...
		
		<p:dataTable id="dar_ac_popDocs_dataTable_docs" value="#{essaiManager.documents}" var="document" emptyMessage="#{resourceBundle['results.none']}">
			<p:column id="nom">
				<f:facet name="header"><h:outputText value="#{resourceBundle['document.nom']}" /></f:facet>
				<h:outputText value="#{document.nom}" />
			</p:column>
			<p:column id="dwd">
				<p:commandLink ajax="false" title="#{resourceBundle['file.dwd']}">
					<h:graphicImage library="images" name="download.gif" alt="#{resourceBundle['file.dwd']}" />
					<p:fileDownload value="#{fileDwdController.downloadDocument(document)}" />
				</p:commandLink>			
			</p:column>
		</p:dataTable>
		...
	</h:form>
</p:dialog>
Download controller :

Code: Select all

public class DocumentDownloadController
{
	 public StreamedContent downloadDocument(final Document doc)
	 {
		InputStream stream = ... ;
        String fileName = ... ;
		String applicationType = ...;
		return new DefaultStreamedContent(stream,
											applicationType,
											fileName);
	 }
}
I have a problem since I have many documents to download in my table.
In fact, it seems that the download-events are not purged when a download occur. Consequently, the next event will be added in the queue events and all of them will be processed. So, it is not the good files that are downloaded.

To illustrate my problem, I have put the fllowing breakpoints in the java code :
B1 : org.primefaces.component.filedownload.FileDownloadActionListener.processAction (l.45)
B2 : DocumentDownloadController.downloadDocument

Exemple that shows the problem :
I have two documents on my table :
doc 1 download 1
doc 2 download 2

STEP 1: click on download 1
1) An event is processed by the FileDownloadActionListener ok
2) My controller is called with doc1 ok
3) The user can download doc 1 ok
STEP 2: click on download 2
1) An event is processed by the FileDownloadActionListener ??
2) My controller is called with doc1 ??
3) An event is processed by the FileDownloadActionListener ok
4) My controller is called with doc2 ok
5) The user can download doc 2 ok
STEP 3 : click on download 1
1) An event is processed by the FileDownloadActionListener ok
2) My controller is called with doc1 ok
3) An event is processed by the FileDownloadActionListener ??
4) My controller is called with doc2 ??
5) The user can download doc 2 KO!

I really don't understand this problem of events processing. How can I solve my problem please?
Thanks.

samalairbien
Posts: 4
Joined: 24 Nov 2010, 16:57

02 Dec 2010, 12:49

For information, I tried to use the first example of p:fileDownload, that means using the p:commandButton instead of p:commandLink, and in this way, the downloads are ok. that's very strange! But I would prefer use the p:commandLink to have a better render.

alexandrepalomo
Posts: 8
Joined: 15 Sep 2010, 21:35

30 Dec 2010, 13:08

samalairbien, I have the same problem you had, but I could not solve it yet =/

I tried using commandLink and commandButton, but I had always the same problem.
After clicking on the button "Download file 1", if I click on "Download file 2", the browser gives me the file 1 again.

I tried using "context.responseComplete();" after downloading the file, but it didn't worked.

can anyone help me with this??

User avatar
Hericksnake
Posts: 47
Joined: 21 Jan 2011, 22:45
Location: Brasil

21 Jan 2011, 22:47

I had the same problem and the solution was using "<h:commandLink>" instead "<p:commandLink>" :D
Primefaces 3.2
JSF 2.0
Glassfish Server 3.1.2
Netbeans7.1.1

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

21 Jan 2011, 22:50


User avatar
Hericksnake
Posts: 47
Joined: 21 Jan 2011, 22:45
Location: Brasil

21 Jan 2011, 22:59

Try to use another "<p:commandLink>" wich makes a redirect to another page.
You will see the problem occur.

The second p:commandLink will do the download, when it should redirect.

I had the same problem as the Thread owner, and resolved it using the described approach.
Primefaces 3.2
JSF 2.0
Glassfish Server 3.1.2
Netbeans7.1.1

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

22 Jan 2011, 00:26

So it is a problem, have you filed an issue?

User avatar
Hericksnake
Posts: 47
Joined: 21 Jan 2011, 22:45
Location: Brasil

22 Jan 2011, 18:24

The issue was created.

http://code.google.com/p/primefaces/iss ... il?id=1656

Feel free to ask anything about it. If you wish, I can post my xhtml an bean that reproduces the error. ;)
Primefaces 3.2
JSF 2.0
Glassfish Server 3.1.2
Netbeans7.1.1

harish.seipl
Posts: 21
Joined: 15 Dec 2010, 07:53

26 Apr 2011, 08:14

Hey i met with a different issue, File download component works fine for the first time when i download the file.But from the second time the whole jsf page is getting downloaded (instead of the downloaded file.)

Iam using view scoped is this was the problem. But i tried in different scopes such as session ,request.
Also iam currently using p:command link.





.
Last edited by harish.seipl on 26 Apr 2011, 08:16, edited 1 time in total.

tricky10
Posts: 79
Joined: 25 Oct 2010, 08:52
Location: Poland

25 May 2011, 13:06

I've also had the same problem with db click. First time was ok but second download the file with the page content not the pdf. The solution was in fact the get method

prvoiusly i had:

public class ReportFileDownloadWrapper {
private ReportQueue reportQueue;
private StreamedContent file;

public StreamedContent getFile() {
return file;
}

public void setFile(StreamedContent file) {
this.file = file;
}

public ReportQueue getReportQueue() {
return reportQueue;
}

public void setReportQueue(ReportQueue reportQueue) {
this.reportQueue = reportQueue;
}


}

The file was added during the lazyLoad. Probably this is a bad approach beacuse the inputstream after first click is closed so the solution was to do it like this:
(to load file every time get is invoked)


public class ReportFileDownloadWrapper {

private static final Logger logger = Logger.getLogger(ReportFileDownloadWrapper.class.getName());
private ReportQueue reportQueue;

public StreamedContent getFile() {
String path = reportQueue.getPath();
if (path != null) {
try {
FileInputStream s = new FileInputStream(path);
StreamedContent file = new DefaultStreamedContent(s, "application/pdf", reportQueue.getType() + "_" + reportQueue.getTimestamp() + ".pdf");
return file;
} catch (FileNotFoundException ex) {
logger.log(Level.SEVERE, null, ex);
reportQueue.setError("File not found");
}
}
return null;
}

public ReportQueue getReportQueue() {
return reportQueue;
}

public void setReportQueue(ReportQueue reportQueue) {
this.reportQueue = reportQueue;
}
}
Glassfish Application Server V3.1.2.2
Primefaces Library 3.5 FINAL
Sun Mojarra 2.1.20

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider] and 25 guests