咱們一般會在EO裏面對某些數據進行驗證,好比在邀請供應商註冊的時候,ORACLE標準邏輯會驗證被邀請的供應商是否已經存在。web
其驗證邏輯在oracle
oracle.apps.pos.schema.server.SupplierRegEOImplapp
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; } }
現因爲客戶以爲標準的異常提示不夠明顯,沒法區分此供應商是已經正式存在的供應商,仍是已經被其餘人邀請過的供應商。學習
因此現決定在保存的時候根據輸入的供應商名稱進行邏輯判斷。spa
經驗證,邏輯判斷不能寫在processFormRequest中,會先執行EO中的驗證。code
不過能夠寫在processFormData中,由於processFormData中的方法是在POST階段執行,因此不會觸發EO中的驗證。orm
新建客戶化CO繼承原有標準COserver
public class CuxSuppRegisterSupplierCO extends SuppRegisterSupplierCO {blog
}繼承
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); } }
參考資料: