Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label Browser. Show all posts
Showing posts with label Browser. Show all posts

Sunday 15 March 2015

Disable(Override) browser back button functionality in ADF Application using JavaScript

This is another JavaScript trick to disable browser back button functionality
In this example i am using two jspx pages - Page1 and Page2



Added two buttons in both pages to navigate between pages



Source of Page1-

<af:outputText value="Page 1" id="ot1" inlineStyle="font-size:medium;font-weight:bold;"/>
                <af:commandButton text="Go To Second Page" id="cb1" action="forward"/>


Source of Page2-


 <af:outputText value="Page 2" id="ot1" inlineStyle="font-size:medium;font-weight:bold;"/>
                <af:commandButton text="Go To First Page" id="cb1" action="backward"/>


Now see JavaScript function to disable back button functionality, In actual JavaScript doesn't disable back button but override it's default functionality
This function forces browser to navigate forward instead of going back so on click of back button first browser executes it's default back operation but due to this function again navigates to forward and show same page


function preventBackButton() {
                  window.history.forward();
              }

Add this javascript to Page 1 and invoke using af:clientListener tag on pageLoad


<af:clientListener method="preventBackButton" type="load"/>

Now run application and check
Go to second page and the press back button - it returns to page one for a fraction of second but again navigates to Page 2
It means it is working , Cheers :) Happy Learning

Saturday 8 March 2014

Launching browser print dialog using simple javascript function in ADF

Hello All ,
This posts 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's 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 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 print button- In Google Chrome

In Mozilla-




after printing, the page look like this
Sample ADF Application- Download
Cheers :-)