Contextual events with EJB DC
By shantala.sankeshwar on Sep 16, 2011
This article describes contextual events with EJB Datacontrol
Use Case Description
Let us consider a scenario wherein the user wants to display deptno list & commandButton in region1 & region2 displays the Emp records corresponding to selected deptno in region1.We will try to achieve this using contextual events.
When the user selects deptno & clicks on the commandButton ,a contextual event with payLoad parameter is broadcasted by taskflow1.This event is then consumed by the taskflow2 and the handleEvent() handler passes payLoad parameter(i.e deptno) to sessionBean.SessionBean has findByDeptno() method that returns the Emp records & taskflow2 displays the respective Emp records .
Let us suppose that we have created Java EE Web Application with Entities from Emp & Dept table
.Also add 'ADF Faces Components 11' under ViewController->project properties-> JSP Tag Libraries.
Edit Emp.java & create a custom named query that returns Emp Object for the respective deptno :
@NamedQuery(name = "findEmpByDeptno", query = "select o from Emp o
where o.dept.deptno = :deptNo")
public void handleEvent(Object payload)
public List<Emp> findEmpByDeptno()
Generate Data control for the above Session Bean & expose the above method through the Session Facade.
Create a ADF taskflow1 with page Fragments & drop view activity(DeptView) on that.In the same taskflow drop Execute operation((findByDeptno()->Emp->Operations->Execute).Define control flow case 'execute' from DeptView to Execute operation in taskflow.
Drop deptno as selectOneChoice & commandButton 'showEmpRecords' on the DeptView page Fragment page.Set showEmpRecords action property as 'execute'
In its page definition create deptno attribute value that points to deptFindAllIterator & handler event method action binding to handle the event:
Select commandButton 'showEmpRecords' & create new contextual event on that:
Now we will create new Event subscriber in its contextual events binding editor tab:
Create taskflow2 that displays Emp table(findByDeptno()->Emp) & create main.jspx page,drop both the taskflows as region
Run the page & now if user selects deptno,table below shows Emp records corresponding to the selected deptno.