Saturday, September 3, 2011

Adf printable page behaviour in page fragment

If you have a requirement for opening a printable page and also the print dialog and you are using page fragments then you should implement the RegionController interface rather than  PagePhaseListener. I had such a requirement and then implemented it using RegionController interface. On any page fragment that you are required to implement this functionality just add an EL expression or a fully classified name of the class that implements the region controller class in the page definition's ControllerClass attribute.  The code snippet for the region controller implementation is shown below.

public boolean refreshRegion(RegionContext regionContext) {

int refreshFlag= regionContext.getRefreshFlag();

FacesContext fctx = FacesContext.getCurrentInstance();

//check internal request parameter

Map requestMap = fctx.getExternalContext().getRequestMap();

PhaseId currentPhase=(PhaseId)requestMap.get("oracle.adfinternal.view.faces.lifecycle.CURRENT_PHASE_ID");

//compare phase


Object showPrintableBehavior =


if (showPrintableBehavior != null) {

if (Boolean.TRUE == showPrintableBehavior) {

ExtendedRenderKitService erks = null;

erks =

Service.getRenderKitService(fctx, ExtendedRenderKitService.class);

//invoke JavaScript from the server

erks.addScript(fctx, "window.print();");





return false;


public boolean validateRegion(RegionContext regionContext) {


return false;


public boolean isRegionViewable(RegionContext regionContext) {

return regionContext.getRegionBinding().isViewable();


This code checks to see if the phase id of current view is Render Response and if so checks whether show printable page behavior was used and if that is indeed the case, It calls the javascript's print function to print the form.
Hope this will be useful to someone who is trying to implement the functionality in adf page fragment.

No comments:

Post a Comment