我们通常会在EO里面对某些数据进行验证,比如在邀请供应商注册的时候,ORACLE标准逻辑会验证被邀请的供应商是否已经存在。
其验证逻辑在
oracle.apps.pos.schema.server.SupplierRegEOImpl
public void setSupplierName(String value) { SupplierRegEntityExpert supplierregentityexpert = getSupplierRegEntityExpert(getOADBTransaction()); if (!supplierregentityexpert.isSupplierValid(value, getSupplierRegId())) { throw new OAAttrValException(121, getEntityDef().getFullName(), getPrimaryKey(), "SupplierName", value, "POS", "POS_SUPPREG_EO_ERR1"); } else { setAttributeInternal(2, value); return; } }
现由于客户觉得标准的异常提示不够明显,无法区分此供应商是已经正式存在的供应商,还是已经被其他人邀请过的供应商。
所以现决定在保存的时候根据输入的供应商名称进行逻辑判断。
经验证,逻辑判断不能写在processFormRequest中,会先执行EO中的验证。
不过可以写在processFormData中,因为processFormData中的方法是在POST阶段执行,所以不会触发EO中的验证。
public void processFormData(OAPageContext pageContext,OAWebBean webBean){ super.processFormData(pageContext, webBean); String str1 = pageContext.getParameter("event"); if (("sendInvitation".equals(str1)) || ("SaveNContinueBtnEvent".equals(str1))) { OAViewObject SupplierRequestsVO = (OAViewObject)pageContext.getApplicationModule((OAWebBean)webBean.findChildRecursive("RegSupplierRN")).findViewObject("SupplierRequestsVO"); String SupplierName = pageContext.getParameter("SupplierName"); Number SupplierRegId = (Number)SupplierRequestsVO.first().getAttribute("SupplierRegId"); LogUtil.of("validSupplierName ",pageContext).print(pageContext); validSupplierName(pageContext,webBean,SupplierName,SupplierRegId); } }
public void validSupplierName(OAPageContext pageContext,OAWebBean webBean, String SupplierName,Number SupplierRegId){ LogUtil.of("validSupplierName fangfa ",pageContext).print(pageContext); OraclePreparedStatement oraclepreparedstatement = null; OracleResultSet oracleresultset = null; OAApplicationModule am = pageContext.getApplicationModule(webBean); try{ oraclepreparedstatement = (OraclePreparedStatement)am.getOADBTransaction().createPreparedStatement(" select vendor_id \n" + "from po_vendors \n" + "where upper(vendor_name) = upper(:1)\n" + "and (start_date_active < sysdate OR start_date_active is null) \n" + "and (end_date_active > sysdate OR end_date_active is null) \n" + "and rownum = 1", 1); oraclepreparedstatement.setObject(1,SupplierName); oracleresultset = (OracleResultSet)oraclepreparedstatement.executeQuery(); if(oracleresultset.next()){ throw new OAException("POS_SUPPREG_EO_ERR1",OAException.ERROR); } } catch(Exception exception1) { throw OAException.wrapperException(exception1); } try{ oraclepreparedstatement = (OraclePreparedStatement)am.getOADBTransaction().createPreparedStatement("SELECT hou.attribute18,\n" + " papf.full_name\n" + " FROM pos_supplier_registrations psr,\n" + " hr_all_organization_units hou,\n" + " fnd_user fu,\n" + " per_all_people_f papf\n" + " WHERE upper(psr.supplier_name) = upper(:1)\n" + " AND psr.supplier_reg_id <> :2\n" + " AND psr.registration_status NOT IN (‘REJECTED‘,\n" + " ‘DRAFT‘,\n" + " ‘RIF_SUPPLIER‘)\n" + " AND rownum = 1\n" + " AND psr.created_by = fu.user_id(+)\n" + " AND psr.ou_id = hou.organization_id\n" + " AND fu.employee_id = papf.person_id(+)\n" + " AND SYSDATE BETWEEN nvl(papf.effective_start_date,\n" + " SYSDATE - 1) AND nvl(papf.effective_end_date,\n" + " SYSDATE + 1)\n", 2); oraclepreparedstatement.setObject(1,SupplierName); oraclepreparedstatement.setObject(2,SupplierRegId); oracleresultset = (OracleResultSet)oraclepreparedstatement.executeQuery(); if(oracleresultset.next()){ String OrgName = oracleresultset.getString(1); String FullName = oracleresultset.getString(2); MessageToken[] tokens = { new MessageToken("ORG_NAME", OrgName), new MessageToken("FULL_NAME", FullName) }; OAException exceptionMessage = new OAException("CUX","CUX_SUPPLIER_HAS_BEEN_INVITED",tokens,OAException.ERROR,null); throw exceptionMessage; //PS1.使用throw直接抛出异常,会导致页面上直接基于EO的字段的数据不会被保留,且不会抛出EO中的验证。 // pageContext.putDialogMessage(exceptionMessage); //PS2.使用putDialogMessage(),页面上的数据被保留,且执行EO中的验证并抛出。 } } catch(Exception exception1) { throw OAException.wrapperException(exception1); } }
参考资料:
1.重新整理后的Oracle OAF学习笔记——5.应用构建基础之实现控制器
时间: 2024-11-06 15:11:46