Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Open a new window programmatically

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Saloon Keeper
Posts: 25816
184
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic