Method call between train flow in ADF | Techartifact

Requirment – To call the method between the train flow in ADF.

For this we need to use outcome property of view. You need to perform following activity.

Wildcard control flow leading to first activity of the train stop, CollateSurveyAnswers.

1. Drag and drop a wildcard flow in task flow.
2. Drag and drop a method call in the taskflow
3. create a navigation case between Wildcard control flow to method call activity.

4. The navigation case name between Wildcard control flow to method call activity is set to outcome property of the view from which you want to call
the method before navigating to that view. For example you are having view1, view2, view3 and view4 in train taskflow.
You want to execute method call before view3.Then you should set the outcome property of view3 to navigation case between Wildcard control flow to method call activity.

5. Create a navigation case from method call to that view.

Note:
The train stop outcome element is used only if an activity such as a method call activity or router is placed prior to the view activity train stop. The element allows you to specify a custom outcome that results in navigation to the train stop.

Enjoy Coding with Techartifact..

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.

prepareSession method in ADF

You can override prepareSession() in your custom Application Module class to do session-specific initializations, such as invoking a stored procedure to initialize the database state for the specific user, store user information, set application-wide configuration parameters based on the user and so on. You may extend the default implementation, as is often nessesary, in order to satisfy various pre-condtions such as user authorization etc. For example, to lock a specific view (E.g. UserView) to only show records with the users own initials (CLB in my case), the following could be done:.The framework invokes prepareSession() when the Application Module is first checked-out from the Application Module pool for a new user session.

Example:

@Override
protected void prepareSession(Session session) {

super.prepareSession(session);

// do session-specific initializations
}

For example we can write the code i.e

 
  public void prepareSession(SessionData sessionData) {
    super.prepareSession(sessionData);
    // Retrieve the J2EE user ID
    String authenticatedUser = getUserPrincipalName();

    if ((authenticatedUser != null) && 
        (authenticatedUser.trim().length() > 0)) {
      DBTransactionImpl dbTransaction = (DBTransactionImpl)getDBTransaction();
      // Parameter for database procedure
      String pApplication = "TUHRA";
      // Transaction statement with procedure call
      CallableStatement callableStmt = 
        dbTransaction.createCallableStatement(("BEGIN " + 
                                               "security_pkg.set_security_context(?, ?); " + 
                                               "END;"), 0);
      try {
        // Register parameters and call procedure
        callableStmt.setString(1, authenticatedUser);
        callableStmt.setString(2, pApplication);
        callableStmt.execute();
      } catch (SQLException sqlExcept) {
        throw new JboException(sqlExcept);
      } finally {
        try {
          if (callableStmt != null) {
            callableStmt.close();
          }
        } catch (SQLException closeExcept) {
          throw new JboException(closeExcept);
        }
      }
    }
  }