Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Pdf showed in new window. Help needed!

631714Apr 2 2008 — edited May 24 2008
Hi all,

This is my first post (but a thousand read), and i want first to thank you all for all the information i have read in this forums for years.

I have a problem which is giving me more problems that i expected. In my webapp, i want to show a pdf document in a new page of the navigator when a button is pressed. I have discarded the target blank option in the container form because i have others buttons and dont want them to be opened in new windows, just the one that open the pdf.

So, I used another navigation rule to open a new window. This page have to make de pdf in code an send it to the client. I dont know how to execute that code on the load of the page.

The solution i am trying is using a poll that only will be called once and in the pollListener execute that code. The problem is that does not work to send the response to the client in the client. Here is the code of the pollListener:

byte[] file; //Don't worry about it. Contains the file pdf i want to show.

FacesContext fctx = FacesContext.getCurrentInstance();

HttpServletResponse response =
(HttpServletResponse) fctx.getExternalContext().getResponse();

response.setContentType("application/pdf");
response.setHeader("Content-Disposition",
"inline; filename=\"file.pdf\"");
response.setHeader("Cache-Control", "no-cache");

response.setContentLength(file.length);

ServletOutputStream sos = response.getOutputStream();
sos.write(fichero);
sos.flush();
sos.close();

fctx.responseComplete();


The curious thing is that if i change the content-disposition to atachemement instead inline, it works asking me to download the file, however, i want it to open directly in the new window and is because of that i use content-disposition inline.

I am almost killing myself because of this problem. Anyone can help me?

Thanks in advance!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 21 2008
Added on Apr 2 2008
10 comments
2,068 views