How to invoke a method from Managed Bean when JSPX Page Loads in ADF

Scenario: In order to restrict the number displayed rows in the table, I have to set the View Criteria on the Iterator before the page loads.

Solution: I have created a method (fetchSourceRecords()) in the Managed bean ( in which I’m setting the View Criteria on the iterator. In order to call this method (fetchSourceRecords()) on Page loads

1) You have to add the below code into your Managed bean (

public void beforePhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {

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

2) Your Managed bean should implements PagePhaseListener as shown below –

public class Attachments implements PagePhaseListener{ }

You have to Import “oracle.adf.controller.v2.lifecycle.PagePhaseListener;”

3) Next, in your JSPX page defination make sure you add the ControllerClass that points to the managed bean that handles the onPageLoad event.

/* PageDef file */
<pageDefinition xmlns=”;
version=”″ id=”SamplePageDef” Package=”com.sample.view


In the Page definition file specify the package path in “Package” attribute and Managed bean class name in “ControllerClass” attribute.

By this whenever you page loads, the onPageLoad() method gets invoked which inturn invokes the fetchSourceRecords() method. You can even call multiple methods in onPageLoad() method.

This entry was posted in ADF (Application Development Framework) and tagged , , , , . Bookmark the permalink.

13 Responses to How to invoke a method from Managed Bean when JSPX Page Loads in ADF

  1. M Sandeep says:

    Hi Udaya Kiran. I have tried to implement this feature. But while page loading, it throws and error saying class I have configured as Managed bean class name in ControllerClass is not found.

  2. M Sandeep says:

    I have figured out the above mentioned problem, however I am facing the below mentioned problem.

    java.lang.ClassCastException: cannot be cast to oracle.adf.model.RegionController

    • udayarocks says:

      Hi Sandeep,
      Thanks for your reply.

      I did not face this error. But I suspect it might be because you have not “implements PagePhaseListener ” in your Managed bean and “Import “oracle.adf.controller.v2.lifecycle.PagePhaseListener;” Check this once.

      Let me know if this does not work and please print the StackTrace in the reply.


      • Kostya says:

        Hi Udaya!
        I’m facing the same problem! Everything is checked:
        Managed Bean:
        “Import “oracle.adf.controller.v2.lifecycle.PagePhaseListener;”
        “…public class backInAssess implements PagePhaseListener{…”
        PageDef: “…ControllerClass=”backings.inDocs.backInAssess”…”

        My page loads fine and OnPageLoad works good to, but when I push the button (method is in this class too) I’m getting:

        java.lang.ClassCastException: backings.inDocs.backInAssess cannot be cast to oracle.adf.model.RegionController

        P.S. Tried to solve this problem in this way:
        “…public class backInAssess implements ControllerClass{…”
        but in this case I could not control beforePhase() and my OnPageLoad did not work.
        Can you help?

      • Kostya says:

        “…public class backInAssess implements PagePhaseListener, RegionController{…”
        Everything works fine now.

  3. Arun M Purushothaman says:

    Thanks for the post, this was definitely useful and it worked fine when I ran the ADF application directly as an app from Jdev. But when I deployed it as an adflibrary and picked the taskflow from Webcenter Spaces, it doesn’t even hit the the lifecycle methods. Need to check if Webcenter doesn’t use lifecycle methods ! Time for an SR.


  4. Mohit Sharma says:

    I am able to execute the method but the control does not go back to the JSPX Page. Can you please suggest what should be done .

  5. none says:

    BEWARE – this approach can only be used for JSPX pages and doesn’t work for Page Fragments (JSFF)! For fragments you have to implement RegionController which doesn’t support so much lifecycle stages.

  6. tareq says:

    i do what mentions here but the class shows me error for LifeSycle and !AdfFacesContext.getCurrentInstance().isPostback()
    what should i do know
    best regards

  7. tareq says:

    dear M Sandeep
    i want to ask how did you solve the java.lang.ClassNotFoundException: Attachments
    please let me know because im facing the same problem

  8. Dennis Kelly says:

    Thanks. The methods worked and loaded data from a database, ran checks and selects for authorization customized for my application all before the page loaded on both the desktop and the web server. Useful information. I use JDev 11.1.2 and WL 10.3.5

    Dennis Kelly

  9. SALEEM says:

    Hi Uday,

    I want customize session expire message and session time out message including the look and feel can help me on this

  10. I do not know if it’s just me or if perhaps everybody else encountering issues with your website. It looks like some of the text on your posts are running off the screen. Can somebody else please comment and let me know if this is happening to them as well? This may be a issue with my browser because I’ve had this happen before.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s