Monday 10 March 2008

Creating Printer Friendly JDev ADF Faces pages

I sat in on an Apex 3.0 class last week and was reminded of a feature that JDeveloper's ADF Faces has had for some time, I just forgot to blog about it!

ADF Faces and ADF Faces RC have an inbuilt feature to provide printer friendly web pages, that is, pages that in printer mode hide the unnecessary components on the page such as buttons and toolbars that would be unwanted on a printed page, instead just showing the data.

In the adf-faces-config.xml file for JDev 10.1.3, and the trindad-config.xml file for JDev 11g TP3, you can set the option output-mode to printable, email or default (null). I show the 11g version here set to printable:

<?xml version="1.0" encoding="windows-1252"?>
<trinidad-config
  xmlns="http://myfaces.apache.org/trinidad/config">
  <output-mode>printable</output-mode>
</trinidad-config>


It's unlikely you would want to hardcode this for your entire application, so luckily the configuration files also support JSF EL expressions. This allows you to rewrite your configuration files to use a JSF managed bean as follows:

<?xml version="1.0" encoding="windows-1252"?>
<trinidad-config
  xmlns="http://myfaces.apache.org/trinidad/config">
  <output-mode>#{UserOptions.printerMode}</output-mode>
</trinidad-config>


...and then switch in and out of the printable mode dependent on what you do in the bean.

The only thing I don't know is the mechanism of which components know to render themselves or hide dependent on the output-mode. Presumably each component has a hidden EL like expression in their rendered property that pays attention to the output-mode.

I also note Oracle hasn't yet documented in the individual component documentation for 11g TP3 if the component is rendered or not under each output-mode, and in turn how to override this functionality if need be. If a reader discovers either please let me know.

No comments: