通过重构VO实现校验功能

现有个需求,需要添加供应商的页面校验功能,当填写一二级时,供应商是必填项,并且所填的供应商必须是二级分类下的,否则下一步和保存过不去:

解决方案:

1.在页面AMXXXImpl.java中,

加入引用:import oracle.jbo.ViewObject;

加入如下方法:

 1 public void lastCheck() {
 2           ZReqLinesVOImpl zreqVO = this.getZReqLinesVO();
 3           int rowCount = zreqVO.getRowCount();
 4           OAException rowException=null;
 5 //          System.out.println("1");
 6 //          System.out.println("rowCount:"+rowCount);
 7               for (int i = 0; i < rowCount; i++)
 8               {
 9              ZReqLinesVORowImpl vendorRow = (ZReqLinesVORowImpl)zreqVO.getRowAtRangeIndex(i);  
10              if(vendorRow.getCate1() != null && vendorRow.getVendorName() == null)//当一二级不为空,供应商名称为空时,提示。
11              {//当填写一二级时,供应商为必填项。请输入第i+1行的供应商。
12                rowException = new OAException("\u5f53\u586b\u5199\u4e00\u4e8c\u7ea7\u65f6\uff0c\u4f9b\u5e94\u5546\u4e3a\u5fc5\u586b\u9879\u3002"+"\u8bf7\u8f93\u5165\u7b2c"+(i+1)+"\u884c\u7684\u4f9b\u5e94\u5546\u3002",OAException.INFORMATION);
13                throw rowException;
14              }
15              if(vendorRow.getVendorName() != null)//当供应商名称不为空时,判断所填的值是否为数据库里存在的供应商
16              {
17                 ViewObject tempVO = this.findViewObject("CuxPoHtVendorTempVO");
18                   if (tempVO == null)
19                   {
20                     StringBuffer stmt = new StringBuffer(1000);
21                 String sql = "";
22                 sql += "select distinct t2.vendor_name,substr(t1.Detl_Path||'.',instr(t1.Detl_Path||'.','.',1)+1,instr(t1.Detl_Path||'.','.',1,2)-instr(t1.Detl_Path||'.','.',1,1)-1)  detl_id";
23                 sql +="  from SMG_ACT_SUPPLIER_TYPE t1,";
24                 sql +="       po_vendors t2,";
25                 sql +="       SMG_SYS_SUP_CLAS_DETAIL t3";
26                 sql +="  where t1.sup_id = t2.segment1";
27                 sql +="       and t3.detl_id = t1.detl_id";
28                 sql +="       and decode(type_expiry_date,null,sysdate,to_date(substr(type_expiry_date,1,8),'yyyymmdd')) >= sysdate";
29                 sql +="       and decode(TYPE_END_TIME,null,sysdate,to_date(substr(TYPE_END_TIME,1,8),'yyyymmdd')) >= sysdate";
30                 sql +="       and decode(type_temp_time,null,sysdate,to_date(substr(type_temp_time,1,8),'yyyymmdd')) >= sysdate";
31                 sql +="       and t2.attribute11='1'";
32                 stmt.append(sql);
33 //                System.out.println(sql);
34                     tempVO = this.createViewObjectFromQueryStmt("CuxPoHtVendorTempVO", stmt.toString());//根据上述sql,创建个临时VO
35                   }
36               String whareString=" 1=1 ";
37               whareString = whareString + " and VENDOR_NAME = " + "'" + vendorRow.getVendorName() + "'";//把供应商名称当做where条件查询
38               whareString = whareString + " and DETL_ID = " + "'" + vendorRow.getCategory2() + "'";//把二级的detl_id当做where条件查询
39               tempVO.setWhereClause(null);
40               tempVO.setWhereClauseParams(null);
41               tempVO.setWhereClause(whareString);
42               tempVO.executeQuery();
43 //              System.out.println(vendorRow.getVendorName());
44 //              System.out.println(vendorRow.getCategory2());//____________
45 //                  System.out.println("2");
46                   Row tempRow = tempVO.first();//判断是否有供应商,若没有,tempRow为空
47 //              System.out.println(tempRow != null);
48                   if (tempRow == null)//当一级二级不为空,且供应商为随便填的值(即tempRow为空),提示。
49                   {
50 //                    System.out.println("3");
51                     //当填写一二级时,供应商为必填项。请输入第i+1行的供应商。
52                     rowException = new OAException("\u5f53\u586b\u5199\u4e00\u4e8c\u7ea7\u65f6\uff0c\u4f9b\u5e94\u5546\u4e3a\u5fc5\u586b\u9879\u3002"+"\u8bf7\u8f93\u5165\u7b2c"+(i+1)+"\u884c\u7684\u4f9b\u5e94\u5546\u3002",OAException.INFORMATION);
53                     throw rowException;
54                   }
55              }
56           
57         
58   }
59   }
View Code

2.在控制“上一步”、“下一步”和“保存”按钮页面的CO中,调用上述方法:

 

OAApplicationModule am = pageContext.getApplicationModule(webBean);
//-------供应商校验-------
      am.invokeMethod("lastCheck");
//------------------------

 

posted @ 2015-01-26 18:36  JOKER-ZHAO  阅读(647)  评论(0编辑  收藏  举报