Friday, October 3, 2014

Passing bind variable value from view criteria(af:query) to next page

Issue/Scenario:

 User performs search on Employee Name and if there is no record in the data base with that name then user would click on Create employee button which takes to create employee page and the employee name should be populated with the name, user entered in the search criteria.

Solution:

Create the view criteria on the view object and create the search form based on the view criteria.

Create java implementation class for the view object on which the View Criteria is defined and make sure you include the bind variable accessors


Select the get method of bind variable and make it available to the client or in other words expose it.


Drag and drop the getinFirstName method on to the task-flow as method activity which will give us the value in the bind variable which user enters while performing the search.

As the user needs to be redirected to Create Employee page and the first name should be populated,. Follow the steps below to achieve the before mentioned.

Open the getinFirstName method page definition file and create a Create Insert operation action binding

Select the getinFirstName method activity on the taskflow and change the value of the method property to managed bean method you just created.



Place the following code in the managed bean method.

    public void createEmployee() {

        OperationBinding op = ADFUtils.findOperation("getinFirstName");
        String name = (String)op.execute();
        JSFUtils.setExpressionValue("#{pageFlowScope.firstName}", name);
        op = ADFUtils.findOperation("CreateInsert");
        op.execute();
    }
 Once you get the bind variable value you can access it either from the page flow scope or you can populate it into the new inserted row.

I am using page flow scope variable to populate the first name in the create employee page.

Your task flow should look as the screen shot below