OAF TABLE中添加序号列

  在实际的OAF页面TABLE的使用中,会有很多时候需要在前台页面中显示序号,虽然在sql中可以使用rownum来获得序号,但是rounum的优先级比order by 高,所以在语句中order by 和rownum混合使用会发现,前面的序号并不是理想中排序的序列号。

  

  所以可以在VO里面新建一个字段用来存放序号的值,初始化VO的时候使用RowSetIterator对结果集进行迭代,然后重置该值。

  同理,可以使用此方法在初始化出一个多行的数据集的时候初始化序列号。

  参考方法如下

 1     public void initRegComplianceVO(){
 2        CuxPosSupplierRegVOImpl suppRegVO = this.getCuxPosSupplierRegVO1();
 3        CuxPosSupplierRegVORowImpl suppRegRow= (CuxPosSupplierRegVORowImpl) suppRegVO.first();
 4        suppRegVO.setCurrentRow(suppRegRow); 
 5         
 6        CuxSuppRegComplianceVOImpl regCompliVO=     this.getCuxSuppRegComplianceVO1();
 7        if(regCompliVO.first()==null){
 8            CuxImportantPromiseVOImpl vo = this.getCuxImportantPromiseVO1();
 9            vo.setMaxFetchSize(-1);
10            vo.executeQuery();
11            
12            RowSetIterator compliIter = vo.createRowSetIterator("compliIter");
13            compliIter.reset();
14            Number rowNum = new Number(0);
15            while(compliIter.hasNext()){
16                Row valueRow= compliIter.next();                
17                CuxSuppRegComplianceVORowImpl row=(CuxSuppRegComplianceVORowImpl)regCompliVO.createRow();
18                rowNum=rowNum.add(1);
19                row.setRowNum(rowNum);
20                row.setComplianceAgreementId(this.getSequenceValue("CUX_SUPP_COMPLIANCE_AGREE_S"));
21                row.setSourceTable("CUX_POS_SUPPLIER_DETAIL_INFO");
22                row.setSourceType("IMPORTANT_PROMISE");
23                row.setSegment(valueRow.getAttribute("LookupCode").toString());
24                row.setDescription(valueRow.getAttribute("Meaning").toString());
25                regCompliVO.last();
26                regCompliVO.next();
27                regCompliVO.insertRow(row);
28  
29            }
30            compliIter.closeRowSetIterator();
31        }
32        
33        else{
34            RowSetIterator compliIter = regCompliVO.createRowSetIterator("compliIter");
35            compliIter.reset();
36            Number rowNum = new Number(0);
37            while(compliIter.hasNext()){
38                CuxSuppRegComplianceVORowImpl compliRow= (CuxSuppRegComplianceVORowImpl)compliIter.next();   
39                rowNum=rowNum.add(1);
40                compliRow.setRowNum(rowNum);
41            }
42            compliIter.closeRowSetIterator();
43        }
44     }

  注:

  1.getCuxPosSupplierRegVO1与getCuxSuppRegComplianceVO1是通过View Link关联的父子结构的VO,使用默认的runNum会取到数据库中的rowNum,而不是当前行的rowNum.

  2.初始化getCuxSuppRegComplianceVO1往其中插入数据的时候遍历了getCuxImportantPromiseVO1,此处根据实际需求完善。

参考:http://blog.csdn.net/amwiacel/article/details/17354235

  

  

原文地址:https://www.cnblogs.com/huanghongbo/p/4503908.html