Use EL to specify the CSS file dynamically, here's an example which checks the presence of the print
request parameter (thus, <h:outputLink value="page.jsf?print" target="_blank">
would suffice):
<link rel="stylesheet" type="text/css" href="${not empty param.print ? 'print.css' : 'normal.css'}" />
You can also retrieve it as a bean proprerty the usual JSF way:
<link rel="stylesheet" type="text/css" href="<h:outputText value="#{bean.cssFile}" /> " />
If you're on Facelets instead of JSP, then you can also use unified EL in template text:
<link rel="stylesheet" type="text/css" href="#{bean.cssFile}" />
If you actually don't need a "print preview" tab/page, then you can also just specify the media
attribute in the CSS link
and let the link/button invoke window.print()
during onclick
instead of opening in a new tab.
<link rel="stylesheet" type="text/css" href="normal.css" media="screen, handheld, projection" />
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
When the page is about to be printed, the one specified by media="print"
will automatically be used instead.