Saturday, October 30, 2010

ADF Model: Programmatically executing view criteria in AMImpl method

This is the most common requirement to execute view criteria of a VO in AMImpl (application module's Impl class). Here is the sample code:

public void getEmployeesInDept(Integer deptId) { if (deptId == null || deptId == 0) { ViewObjectImpl empDeptVO = this.getEmpDeptVO(); //View Criteria without bind variable ViewCriteria vc = empDeptVO.getViewCriteria("noRowsVC"); empDeptVO.applyViewCriteria(vc); empDeptVO.executeQuery(); } else { ViewObjectImpl empDeptVO = this.getEmpDeptVO(); //View Criteria with bind variable 'Bind_deptId' empDeptVO.setApplyViewCriteriaName("findByDeptId"); empDeptVO.setNamedWhereClauseParam("Bind_deptId", deptId); empDeptVO.executeQuery(); } }


The above method shows how to execute view criterias "noRowsVC"(with no bind variables) and "findByDeptId"(which has a bind variable "Bind_deptId") in EmpDeptVO. The below screenshots show the view criterias in EmpDeptVO.

That's it. The method executes the VC and gets the query results. You can expose this method in client's interface and add this method in jsff pagedef file as a methodAction binding. The later post shows how to pass parameters and call/execute this AMImpl method ( i.e., getEmployeesInDept) in UI project's java bean.

5 comments:

Related Posts with Thumbnails