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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 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 if(currentPhase.getOrdinal()==PhaseId.RENDER_RESPONSE.getOrdinal()){ Object showPrintableBehavior = requestMap.get("oracle.adfinternal.view.faces.el.PrintablePage"); 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();"); } } } regionContext.getRegionBinding().refresh(refreshFlag); return false; } public boolean validateRegion(RegionContext regionContext) { regionContext.getRegionBinding().validate(); 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.