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