Launching browser print dialog using simple javascript function in ADF

Sharing is Caring

Hello All,
This post talks about a requirement of printing a simple page (not much component as, form, tree, etc & not much data)
you can use a simple one-liner javascript function to invoke browser print dialog.

  • There is a page with Departments table on it, and a button to print this page

 

  • Called this simple javascript function on button click to open the print dialog

window.print();

 

  • To execute javascript through managed bean use this method

    /**Method to execute Javascript
     * @param javascriptCode
     */
    public static void runJavaScriptCode(String javascriptCode) {
        FacesContext facesCtx = FacesContext.getCurrentInstance();
        ExtendedRenderKitService service = Service.getRenderKitService(facesCtx, ExtendedRenderKitService.class);
        service.addScript(facesCtx, javascriptCode);
    }

 

  • Click on the print button- In Google Chrome

In Mozilla-

browser print dialog

after printing, the page looks like this

Sample ADF Application- Download
Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

Leave a Reply

Your email address will not be published. Required fields are marked *