OAF_開發系列01_實現OAF資料主從關係Master-Detail聯動(案例)

2014-06-02 Created By BaoXinjianweb

1、摘要post


OAF和Form Builder同樣,也須要主從塊的管理,應爲Form只須要創建一個relationship,相對簡單測試

在OAF中實現主從Master-Detail聯動的實現,更多的是經過代碼去實現ui

好比在主塊中添加一個event,在CO中去觸發從塊的查詢語句,從而實現聯動this

我的以爲其核心思想就是,在Master Section中換行時,觸發一個Event,在CO中一旦獲取這個Event後,調用AM中的方法對Detail Section的VO進行查詢初始化spa

 

2、案例code


需求:當主塊supplier選擇後,系統自動關聯子塊Site,顯示這個supplier下的全部sitesorm

1. 創建Header Region -> Supplier Tableblog

2. 創建Detail Region -> Supplier Sites Tabletoken

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

 

3、案例實現


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 }
複製代碼

 

4、案例測試


Test. 查看結果

Test1. 查詢Supplier Header,選中第一條Record
    

Test2. 選中第一條後,在Detail中顯示全部Site Records

    

 

Thanks and Regards

相關文章
相關標籤/搜索