This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes Open a new window programmatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Open a new window programmatically" Watch "Open a new window programmatically" New topic
Author

Open a new window programmatically

D. Formenton
Ranch Hand

Joined: Mar 20, 2008
Posts: 47
I need to display a file. pdf in a new window (or, rather, in a new tab), other than that used by the application.

The following function shows the file correctly, but unfortunately overwrite the main application window.

What changes should I make to the code to make the pdf file opens in a new window?

Thank you.

Domenico
John Burton
Greenhorn

Joined: Mar 26, 2012
Posts: 5
You could change the target of the command link you are calling that code from. I think "_blank" will open a new window.



Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

You should not attempt to use JSF to render pages that are not in HTML format (such as PDFs and Excel spreadsheets). Use a servlet to render the PDF.

Normally, thanks to the Eolas lawsuit, an attempt to open a PDF in a Microsoft Internet Explorer window will instead result in a new, non-IE window being opened, so unless you're using a non-Microsoft browser, if it replaced what was in your browser window, what you got wasn't a true PDF, it was PDF corrupted by the things JSF does because it thought you were attempting to output an HTML web page.

To reliably open a PDF in an external window, output the PDF from a plain-vanilla servlet and set the "target" attribute on the commandLink of the JSF form that provides the servlet URL to fetch/create the PDF and set your Content-Disposition header appropriately. Note that "target" is not an option on the JSF commandButton, so if you want a "button", tart up a commandLink with suitable button-looking graphics and CSS settings.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Open a new window programmatically
 
Similar Threads
Multiple Actions issue in JSF
showing pdf in Fire fox giving problem
A problem with servlet file transfer
Opening a PDF
What's the best way to download files from a web app?