Tuesday 3 March 2015

Automatic button click in ADF using Java Script

Some time we want to perform a click operation automatically on page load. Consider a scenario where we want to call managed bean on page load event.
To achieve this::


  • Create a jsp or jspx page.
  • Drag & Drop button component inside form.
 <af:button text="click" id="b3" binding="#{backingBeanScope.backing_Shelf.b3}"  
          visible="false"  
          actionListener="#{backingBeanScope.backing_Shelf.callRowFinder}"  
      clientComponent="true"/>   
  •  On page inside <document > tag you can search for <resource> tag. 
  •  First create resource tag, select type="javascript". ( Type defines which type of function you will be keeping inside resource tag, it can be either javascript or css)
  • Create a function such as "invokeOnLoad" inside resource tag. To locate button component onto page pass button id inside method (which button you want to click). In my case button id is "b3". 

Method


  <af:resource type="javascript">  
         function invokeOnLoad() {  
             var button = AdfPage.PAGE.findComponentByAbsoluteId('b3');  
             AdfActionEvent.queue(button, true);  
             event.cancel();  
         }  
     </af:resource>  
  • Now its time to call  method. To achieve this inside <Document> tag,  client listener tag is present, this tag has load property. It invokes method during document load.
                 <af:clientListener method="invokeOnLoad" type="load"/>


Note::
If you use "AdfActionEvent.queue(button)" instead of "AdfActionEvent.queue(button,true) then   button click will occur infinity times. 

No comments:

Post a Comment