zoukankan      html  css  js  c++  java
  • 标准的EO验证提示错误不够完整,抛出自定义的异常。

     我们通常会在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中的验证。

    新建客户化CO继承原有标准CO

    public class CuxSuppRegisterSupplierCO extends SuppRegisterSupplierCO {

    }

        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 
    " + 
                                                                                                                    "from po_vendors  
    " + 
                                                                                                                    "where upper(vendor_name) = upper(:1)
    " + 
                                                                                                                    "and (start_date_active < sysdate OR start_date_active is null) 
    " + 
                                                                                                                    "and (end_date_active > sysdate OR end_date_active is null) 
    " + 
                                                                                                                    "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,
    " + 
                                                                                                                    "       papf.full_name
    " + 
                                                                                                                    "  FROM pos_supplier_registrations psr,
    " + 
                                                                                                                    "       hr_all_organization_units  hou,
    " + 
                                                                                                                    "       fnd_user                   fu,
    " + 
                                                                                                                    "       per_all_people_f           papf
    " + 
                                                                                                                    " WHERE upper(psr.supplier_name) = upper(:1)
    " + 
                                                                                                                    "   AND psr.supplier_reg_id <> :2
    " + 
                                                                                                                    "   AND psr.registration_status NOT IN ('REJECTED',
    " + 
                                                                                                                    "                                       'DRAFT',
    " + 
                                                                                                                    "                                       'RIF_SUPPLIER')
    " + 
                                                                                                                    "   AND rownum = 1
    " + 
                                                                                                                    "   AND psr.created_by = fu.user_id(+)
    " + 
                                                                                                                    "   AND psr.ou_id = hou.organization_id
    " + 
                                                                                                                    "   AND fu.employee_id = papf.person_id(+)
    " + 
                                                                                                                    "   AND SYSDATE BETWEEN nvl(papf.effective_start_date,
    " + 
                                                                                                                    "                           SYSDATE - 1) AND nvl(papf.effective_end_date,
    " + 
                                                                                                                    "                                                SYSDATE + 1)
    ", 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.应用构建基础之实现控制器

    2.OAF—Row的状态

  • 相关阅读:
    $w=$mysqli>query($sql);
    yield 异步 并行 Promise await async
    First normal formal Second normal form
    :avalon及通用MVVM的设计原理分析
    MySQL 超时时间timeout
    referrer privacy hotlinking
    SET NAMES
    a loosely strongly typed language
    内部排序 外部排序 稳定排序 不稳定排序
    97.394570112228 Query OK, 1 row affected (43.05 sec) the overhead of parsing and network communication
  • 原文地址:https://www.cnblogs.com/huanghongbo/p/4864674.html
Copyright © 2011-2022 走看看