ADF 11G : How to Implement Print functionality in ADF?
APPROACH-1
public void beforePhaseMethod(PhaseEvent phaseEvent) {
//only perform action if RENDER_RESPONSE phase is reached
if (phaseEvent.getPhaseId() == PhaseId.RENDER_RESPONSE){
FacesContext fctx = FacesContext.getCurrentInstance();
//check internal request parameter
Map requestMap = fctx.getExternalContext().getRequestMap();
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();");
}
}
}
}
***********************************************
APPROACH-2
Just call the window.print()
public String print() {
// Add event code here...
FacesContext facesContext = FacesContext.getCurrentInstance();
org.apache.myfaces.trinidad.render.ExtendedRenderKitService service =
org.apache.myfaces.trinidad.util.Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
service.addScript(facesContext, "window.print();");
return null;
}