Monday, September 9, 2019

Invoke a method from Managed Bean when JSPX Page Loads in ADF.

Requirment -invoke a method from Managed Bean when JSPX Page Loads in ADF.

Suppose you have some method in managed bean, which you want to call on page load.For that
Your managed bean should implement implements PagePhaseListener i.e
public class vinayManagedBean implements PagePhaseListener{ }
You should import “oracle.adf.controller.v2.lifecycle.PagePhaseListener;”
Now you will be calling method in beforePhase event of ADF page life cycle.In side the beforePhase ,pageLoad method will be called.You can write your custom method there.
public void beforePhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
onPageLoad();
}
}
 
public void afterPhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
// onPagePreRender();
}
}
 
public void onPageLoad() {
if (!AdfFacesContext.getCurrentInstance().isPostback()) {
// add your onPageLoad event here
 
// to set the View Criteria on the Iterator
doSomeOperation();  ///your custom method.
}
}
After all then right click on .jspx page and go to page definitions file .In your JSPX page definition make sure you add the ControllerClass that points to the managed bean that handles the onPageLoad event.
<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" version="11.1.2.60.17" id="InspectionTaskHomePageDef"
                Package="oper.view.pageDefs" ControllerClass="vinayManagedBean">
  <parameters/>
By doint this whenever you page loads, the onPageLoad() method gets invoked which inturn invokes the v() method. You can even call multiple methods in onPageLoad() method.
Note:- It will not work in jsff.

No comments:

Post a Comment