I need to make a link which opens print version of current page in a new tab. I already have correspondent css-file. But I don’t know how to specify when this file should be used instead of standard.
The simplest way is quite good. If I was using JSP I would simply add get parameter to print-link URL. Is there any way to achieve similar results with jsf?
Use EL to specify the CSS file dynamically, here’s an example which checks the presence of the
printrequest parameter (thus,<h:outputLink value="page.jsf?print" target="_blank">would suffice):You can also retrieve it as a bean proprerty the usual JSF way:
If you’re on Facelets instead of JSP, then you can also use unified EL in template text:
If you actually don’t need a “print preview” tab/page, then you can also just specify the
mediaattribute in the CSSlinkand let the link/button invokewindow.print()duringonclickinstead of opening in a new tab.When the page is about to be printed, the one specified by
media="print"will automatically be used instead.