Showing posts with label call java method after page load in ADF. Show all posts
Showing posts with label call java method after page load in ADF. Show all posts

Thursday, October 7, 2021

Oracle ADF-Calling Java Script/java method on page load of .jspx/.jsf

Requirement-In ADF application we often come across requirement where we want to call JavaScript method or java Method on page load or after load o  of .JSPX or .JSF page.


Solution:

First step is to add clientListener onBodyLoad method which gets called on load of page as below

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





Java script method as below















Above you can notice I am firing the click event by finding component “main” which is panel group layout as below.

Since there is af:clientListener added inside af:panelGroupLayout onMainClick method  get called.























onMainClick javascript function i am getting OS type of client and passing it to serverListener which is getting called by queueing the event as below





In the bean method of server Listener I am just reading the OS type that is passed and putting it in sessionScope and then refresh output text to show the OS type on UI as below


    public void onTemplateLoad(ClientEvent clientEvent) {

           // Add event code here...

           String osType = (String) clientEvent.getParameters().get("osType");

          

           System.out.println("Os type-"+osType);

       

           ADFContext.getCurrent().getSessionScope().put("OSTYPE", osType);

           AdfFacesContext.getCurrentInstance().addPartialTarget(panelGroupBinding);

 

       }

When you run page it shows first the alert as below




















And then shows OS type as below