Using a task flow initializer to initialize a task flow

To initialize, there are two ways of doing that.either using method call activity and using initializer of task flow.

An initializer is custom code that is invoked when an ADF bounded task flow is entered. You specify both the initializer and finalizer as an EL expression for a method on a managed bean, for example, #{pageFlowScope.modelBean.releaseResources}.

When to use what.

Use a method call activity – -No reentry via back button expected: Designate a method call activity as the default activity (first to execute) in the ADF bounded task flow. The method call activity calls a custom method containing the intializer code.

Use a Initializer of TaskFlow- Back button reentry possible: Specify an intializer method using an option on the ADF bounded task flow metadata. Use this technique if you expect that a user may reenter the task flow using a browser back button. In such a case, the designated default activity for the bounded task flow may never be called, but a method designated using the Initializer method will.

Now we will see how we can implement that-

Write a method which we need to call before taskflow in applicationModuleImpl.java .Expose to client interface of application module so that it will come in data control

 public void prepare() {
// get the Employees view object instance
EmployeesImpl employees = this.getEmployees();
// remove all rows from rowset
employees.executeEmptyRowSet();
// create a new employee row
Row employee = employees.createRow();
// add the new employee to the rowset
employees.insertRow(employee);
}

– Right-click on the ViewController project in the Application Navigator and select New…. Select ADF Task Flow from the Web Tier | JSF/Facelets category.

– In the Create Task Flow dialog, enter taskflowInitializer.xml for the task flow File Name and ensure that you have selected the Create as Bounded Task Flow
checkbox. Also make sure that the Create with Page Fragments checkbox is not selected. Then click OK.

– The taskflowInitializer task flow should open automatically in Diagram mode. If not, double-click on it in the Application Navigator to open it. Click anywhere in
the task flow, then in the Property Inspector change the URL Invoke property to urlinvoke-allowed.

– Go to the task flow Overview | Managed Beans section and add a managed bean called InitializerBean. Enter com.techartifact.jdeveloper.hr.main.view.beans.Initializer for the managed bean Class and select pageFlow for the bean Scope

– While at the Managed Beans section, select Generate Class from the Property Menu next to the Managed Bean Class in the Property Inspector.

– Locate the Initializer.java bean in the Application Navigator and open it in the Java editor. Add the following initialize method to it

public void initialize() {
// get the application module
HrComponentsAppModule hrComponentsAppModule =
(HrComponentsAppModule)ADFUtils
.getApplicationModuleForDataControl(
"HrComponentsAppModuleDataControl");
if (hrComponentsAppModule != null) {
// call the initializer method
hrComponentsAppModule.prepare();
}
}

– Return to the task flow, diagram and add a task flow initializer by clicking on the Property Menu next to the Initializer property in the Property Inspector and
selecting Method Expression Builder.

– In the Expression Builder dialog that opens, locate and select the initialize method of the InitilizerBean under the ADF Managed Beans node. The click OK to dismiss
the dialog. The initializer expression #{pageFlowScope.InitializerBean.initialize} should be reflected in the Initializer property of the task flow in the
Property Inspector.

Thats it.

finalizer is also an important part.finalizer is custom code that is invoked when an ADF bounded task flow is exited via a task flow return activity or because an exception occurred. The finalizer is a method on a managed bean. Common finalizer tasks include releasing all resources acquired by the ADF bounded task flow and perform cleanup before exiting the task flow.

Happy coding with Techartifact with Vinay ….

Get value of LOV/choiceList programmaticaly in bean instead of index in Oracle ADF

Requirment-Get value of LOV/choiceList programmaticaly in bean instead of index in Oracle ADF

When you wrote like In backing bean we get the index, not the value. most of the developer did this mistake.

JSFUtils.resolveExpression(“#{bindings.EmployeeId.inputValue}”); —- We got the index

Instead of use attributeValue to get the value in bean.use this code in the bean or as the EL

JSFUtils.resolveExpression(“#{bindings.EmployeeId.attributeValue}”);

Commonly ADF Security Expression Language -el

Name of authenticated user – #{securityContext.userName}

Check if user logged in – #{securityContext.authenticated}

Check if user is a member of at least one role in comma separated list – #{securityContext.userInRole[‘roleList’]}

Check if user is a member of all roles in comma separated list – #{securityContext.userInAllRoles[‘roleList’]}

True if the user has access rights,Where resource is a string containing
a semicolon-separated concatenation f resourceNameReturns.True if the
user has access rights – #{securityContext.userGrantedResource[‘resource’]}