• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Open a new window programmatically

 
D. Formenton
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18281
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic