2014-06-02
BaoXinjian
一、摘要
OAF和Form Builder一样,也需要主从块的管理,应为Form只需要建立一个relationship,相对简单
在OAF中实现主从Master-Detail联动的实现,更多的是通过代码去实现
比如在主块中添加一个event,在CO中去触发从块的查询语句,从而实现
二、案例
需求:当主块supplier选择后,系统自动关联子块Site,显示这个supplier下的所有sites
1. 建立Header Region -> Supplier Table
2. 建立Detail Region -> Supplier Sites Table
3. 在Header中建立Singel Section, 设定Action Type为FireAction,
Event为SupplierSelect
4. 新增CO,在ProcessFormRequest中抓取Event SupplierSelect,调用AM的方法
5. 在AM中获取Supplier_Id, 将Supplier_Id赋值与VO中的具体SQL
6. VO中执行SQL
7. 查看结果
(1). 查询Supplier Header,选中第一条Record
(2). 选中第一条后,在Detail中显示所有Site Records
三、案例实现
Step1. 建立Structure
Step2. 新增CO,在ProcessFormRequest中抓取Event
SupplierSelect,调用AM的方法
1 public void processFormRequest(OAPageContext pageContext, OAWebBean webBean) {
2
3 super.processFormRequest(pageContext, webBean);
4
5 OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean);
6
7 String event = pageContext.getParameter("event");
8
9 if ("supplierSelect".equals(event)){
10
11 am.invokeMethod("handleSupplierSelectionEvent");
12
13 }
14
15 }
Step3. 在AM中获取Supplier_Id, 将Supplier_Id赋值与VO中的具体SQL
1 public void handleSupplierSelectionEvent(){
2
3 OADBTransaction txn = getOADBTransaction();
4
5 String detailTableText = null;
6
7 String supplierId = null;
8
9 OAViewObject vo = (OAViewObject)findViewObject("SupplierVO1");
10
11 Row masterRow = vo.getFirstFilteredRow ("SelectFlag", "Y");
12
13 if (masterRow != null){
14
15 vo.setCurrentRow(masterRow);
16
17 supplierId = String.valueOf(masterRow.getAttribute("SupplierId"));
18
19 MessageToken[] tokens = { new MessageToken("SUPPLIER_NAME", null)};
20
21 detailTableText = txn.getMessage("AK", "FWK_TBX_SITES_FOR_SUPPLIER", tokens);
22
23 }
24
25 else{
26
27 detailTableText = txn.getMessage("AK", "FWK_TBX_SUPPLIER_SITES", null);
28
29 }
30
31 SupplierSitesVOImpl voSites = this.getSupplierSitesVO1();
32
33 if (voSites == null){
34
35 MessageToken[] errTokens = { new MessageToken("OBJECT_NAME","SupplierSitesVO1")};
36
37 throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", errTokens);
38
39 }
40
41 voSites.initQuery(supplierId);
42
43 }
Step4. VO中执行SQL
1 public void initQuery (String SupplierId) {
2
3 if (SupplierId != null){
4
5 setWhereClause("SUPPLIER_ID = :1");
6
7 setWhereClauseParams(null); // Always reset
8
9 setWhereClauseParam(0, SupplierId);
10
11 executeQuery();
12
13 }
14
15 }
四、案例测试
Test. 查看结果
Test1. 查询Supplier Header,选中第一条Record
Test2. 选中第一条后,在Detail中显示所有Site Records