Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem trying to send file to browser in JSF

 
Stefan Rasmusson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using "application/force-download" instead of "text/plain".

Regrds,
Prasenjit
 
Stefan Rasmusson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic