Sunday, 22 February 2015

Clicking on a button using Javascript in adf until all the adf components are processed



About:

In this blog i will be explaining on how to execute a hidden button virtually in ADF until all the page components are loaded

Description:

Consider a scenario where you want to perform some operation on a component on page load by click on the button, sometimes that component may not be loaded when the button executes, this may cause errors.

This can be handled by using the adf javascript api's to verify whether the page is fully synchronized before the button is called virtually

Java Script Code

   function invokeLoadEvnt() {
                  if (window.AdfPage && window.AdfPage.PAGE &&   window.AdfPage.PAGE.isSynchronizedWithServer()) {
                      alert('I am Synchronized');
                      var button = AdfPage.PAGE.findComponentByAbsoluteId('b1');
                      AdfActionEvent.queue(button,true);
                  }
                  else {

                      alert('Retry Once again');
                      window.setTimeout(invokeLoadEvnt, 10000);
                  }
              }

In the jspx page under the af:document call the client listener

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