Wednesday, January 9, 2013

ADF : How to call a method on Page Load ?

ADF : How to call a method on Page Load ?

Use case : We have a jspx page welcome.jspx. We have to call a custom method(onPageLoadWelcome) before loading the jspx page.

Approach 1: Work with Event.



     fig: jspx page




  private void onPageLoad(PhaseEvent phaseEvent){
    System.out.println("Called onPageLoad by Neelmani");
    }
            fig: onPageLoad method as the part of Backing Bean
 



     fig: OutPut


NOTE: Some times afterPhase() and beforePhase() will get executed multiple times. How to restrict them?
Solution:
    public void beforePhase(PhaseEvent phaseEvent){
      
        if(phaseEvent.getPhaseId().toString().equalsIgnoreCase("RENDER_RESPONSE 6")){

            onPageLoad();
           
            }
       
        }
   
    public void onPageLoad(){
        System.out.println("onPageLoad");
        }




Approach 2: Write the custom method, create Datacontrol and call it onPageLoad

 

Fig : Created an Interface with the method declaration onPageLoadWelcome()









Fig : Created the implementation class for the Interface 






Fig : Extends the implementation class







Fig : Created the Data Control from the implementation class





Fig : Data Control of that implementation class






Fig : Create a method binding under the welcome page





Fig : Action Binding Dialog under the welcome page





Fig : Invoke Action Dialog under the welcome page







Fig : Invoke Action Property Dialog under the welcome page





Fig : Run the welcome page







Fig : Method got called before page load: the welcome page


************************************************************

Open af:popup onPageLoad