wood burning stoves 2.0*
The moose likes JSF and the fly likes Problem trying to send file to browser in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Problem trying to send file to browser in JSF" Watch "Problem trying to send file to browser in JSF" New topic
Author

Problem trying to send file to browser in JSF

Stefan Rasmusson
Greenhorn

Joined: Feb 25, 2010
Posts: 5
Hi I've tried two different techniques for sending a file to a browser(making the user download a file). I've tried an example from myfaces wikipage


I have also tried using a component named fileDownload from PrimeFaces. Both give the same result:

I get a response from the server, the response contains text that should be in the file. The header is a follows:

X
To me this looks correct but for some reason I don't get to download the file, I just get this response in firebug.

Does anyone have any idea?, could it be a serversetting problem? I using glassfish 3

Thanks / Stefan
prasenjitkumar das
Greenhorn

Joined: Mar 17, 2010
Posts: 12
Try using "application/force-download" instead of "text/plain".

Regrds,
Prasenjit
Stefan Rasmusson
Greenhorn

Joined: Feb 25, 2010
Posts: 5
It didn't work. I think the problem lies in JSF and facelets. I use a facelet and a template.

Template



Facelet




But if I rewrite the facelet like this, the download works, and it works with the mimetype text/plain




Any ideas?
Janardan Thakar
Greenhorn

Joined: May 21, 2010
Posts: 2
Try this.
response.setContentType("application/vnd.ms-word");

Because for the plain text some time browser displays content directly in the screen instead of giving download option.
Stefan Rasmusson
Greenhorn

Joined: Feb 25, 2010
Posts: 5
It figured out the problem.
I was using the primefaces commad button that does a partial ajax submit. Changed to jsf commandbutton and everything works
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem trying to send file to browser in JSF