现有个需求,需要添加供应商的页面校验功能,当填写一二级时,供应商是必填项,并且所填的供应商必须是二级分类下的,否则下一步和保存过不去:
解决方案:
1.在页面AM的XXXImpl.java中,
加入引用:import oracle.jbo.ViewObject;
加入如下方法:
public void lastCheck() {
ZReqLinesVOImpl zreqVO = this.getZReqLinesVO();
int rowCount = zreqVO.getRowCount();
OAException rowException=null;
// System.out.println("1");
// System.out.println("rowCount:"+rowCount);
for (int i = 0; i < rowCount; i++)
{
ZReqLinesVORowImpl vendorRow = (ZReqLinesVORowImpl)zreqVO.getRowAtRangeIndex(i);
if(vendorRow.getCate1() != null && vendorRow.getVendorName() == null)//当一二级不为空,供应商名称为空时,提示。
{//当填写一二级时,供应商为必填项。请输入第i+1行的供应商。
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);
throw rowException;
}
if(vendorRow.getVendorName() != null)//当供应商名称不为空时,判断所填的值是否为数据库里存在的供应商
{
ViewObject tempVO = this.findViewObject("CuxPoHtVendorTempVO");
if (tempVO == null)
{
StringBuffer stmt = new StringBuffer(1000);
String sql = "";
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";
sql +=" from SMG_ACT_SUPPLIER_TYPE t1,";
sql +=" po_vendors t2,";
sql +=" SMG_SYS_SUP_CLAS_DETAIL t3";
sql +=" where t1.sup_id = t2.segment1";
sql +=" and t3.detl_id = t1.detl_id";
sql +=" and decode(type_expiry_date,null,sysdate,to_date(substr(type_expiry_date,1,8),'yyyymmdd')) >= sysdate";
sql +=" and decode(TYPE_END_TIME,null,sysdate,to_date(substr(TYPE_END_TIME,1,8),'yyyymmdd')) >= sysdate";
sql +=" and decode(type_temp_time,null,sysdate,to_date(substr(type_temp_time,1,8),'yyyymmdd')) >= sysdate";
sql +=" and t2.attribute11='1'";
stmt.append(sql);
// System.out.println(sql);
tempVO = this.createViewObjectFromQueryStmt("CuxPoHtVendorTempVO", stmt.toString());//根据上述sql,创建个临时VO
}
String whareString=" 1=1 ";
whareString = whareString + " and VENDOR_NAME = " + "'" + vendorRow.getVendorName() + "'";//把供应商名称当做where条件查询
whareString = whareString + " and DETL_ID = " + "'" + vendorRow.getCategory2() + "'";//把二级的detl_id当做where条件查询
tempVO.setWhereClause(null);
tempVO.setWhereClauseParams(null);
tempVO.setWhereClause(whareString);
tempVO.executeQuery();
// System.out.println(vendorRow.getVendorName());
// System.out.println(vendorRow.getCategory2());//____________
// System.out.println("2");
Row tempRow = tempVO.first();//判断是否有供应商,若没有,tempRow为空
// System.out.println(tempRow != null);
if (tempRow == null)//当一级二级不为空,且供应商为随便填的值(即tempRow为空),提示。
{
// System.out.println("3");
//当填写一二级时,供应商为必填项。请输入第i+1行的供应商。
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);
throw rowException;
}
} }
}
2.在控制“上一步”、“下一步”和“保存”按钮页面的CO中,调用上述方法:
OAApplicationModule am = pageContext.getApplicationModule(webBean);
//-------供应商校验-------
am.invokeMethod("lastCheck");
//------------------------