Wednesday, November 16, 2011

ADF: How-to launch browser print dialog when showing printable page

The following code, when referenced from the beforePhase property of the f:view component, automatically opens the browser print dialog if a page is rendered as printable.
To this time however I used an internal flag, which doesn't feel right. The code used in this post only uses public APIs and thus is a solution that lasts.

The managed bean method is referenced from the f:view component as follows
<f:view beforePhase="#{SampleBean.beforePhaseMethod}">
With this listener and code, when the af:showPrintableBehavior tag is used on a command item to show a printable page, the browser print dialog is automatically opened. 
While the same code also works for page fragments, the f:view tag is only available for JSPX documents. In this case you either set the beforePhase method property on the JSPX document hosting the page fragment, or define a global phase listener (faces-config.xml) that then works for all pages in an application.

No comments :

Post a Comment