OAF_开发系列13_实现OAF通过Vector动态查询设置(案例)

20150715 Created By BaoXinjian

OAF_开发系列13_实现OAF通过Vector动态查询设置(案例)一、摘要


Oracle OAF Guide上介绍的标准客制化查询的方式,在多条件下进行查询

具体实现步骤如下

Step1.在controler中的processRequest 的方法中调用

(1). am.invokeMethod("vectorQuery", parameters);

(2). 当然要调用invokeMethod方法先要 OAApplicationModule am = pageContext.getApplicationModule(webBean) 来实例化am;、;

(3). initDetails是写在AM的java 文件的中的一个方法,parameters可以用pageContext.getParameters 方法得到你想要的任何参数;

Step2. 在AM的java文件中写一个vectorQuery方法函数,来调用VO中的方法。

Step3. 在VO中添加下面的代码,这个代码是从OAF的UG里面拿出来的,我觉得这段代码比较的经典,以后在开发中会不断的用到;

 

OAF_开发系列13_实现OAF通过Vector动态查询设置(案例)二、实现方式


1.  创建查询页面如下,新增按钮SearchEmployee,并触发时间Search

OAF_开发系列13_实现OAF通过Vector动态查询设置(案例)

 

2. 在CO中新增方法,获取Search时间,并调换用AM中的实现方法

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    
    if ("Search".equals(pageContext.getParameter(EVENT_PARAM))) {
        String p_employee_num = pageContext.getParameter("EmployeeNumQ");
        String p_employee_name = pageContext.getParameter("EmployeeNameQ");
        String p_employee_country = pageContext.getParameter("EmployeeCountryQ");
        Serializable[] params = {p_employee_num, p_employee_name, p_employee_country};
        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        am.invokeMethod("vectorQuery",params);
    }  
}

 

3.  在AM中创建实现方法,最为关键的一步

public void vectorQuery(String p_employee_num, String p_employee_name, String p_employee_country) {
   
   //VO初始化
   EmployeesVOImpl employeevo = this.getEmployeesSearchVO();
   
   //参数初始化
   StringBuffer whereClause = new StringBuffer(100);
   Vector parameters = new Vector(3);
   int clauseCount = 0;
   int bindCount = 0;
   
   //加入第1个条件Employee Num
   if ((p_employee_num != null) && (!("".equals(p_employee_num.trim()))))
   {
     whereClause.append(" EMPLOYEE_NUM like :");
     whereClause.append(++bindCount);
     parameters.addElement("%" + p_employee_num + "%");
     clauseCount++;
   }
   
   //加入第2个条件Employee Name
   if ((p_employee_name != null) && (!("".equals(p_employee_name.trim()))))
   {
     if (clauseCount > 0) {
       whereClause.append(" AND ");
     }
     whereClause.append(" EMPLOYEE_NAME like :");
     whereClause.append(++bindCount);
     parameters.addElement( "%" + p_employee_name + "%");
     clauseCount++;
   }
   
   //加入第3个条件Employee Country
   if ((p_employee_country != null) && (!("".equals(p_employee_country.trim()))))
   {
     if (clauseCount > 0) {
       whereClause.append(" AND ");
     }
     whereClause.append(" EMPLOYEE_COUNTRY like :");
     whereClause.append(++bindCount);
     parameters.addElement("%" + p_employee_country + "%");
     clauseCount++;
   }
   
   //VO查询WhereCause和Parameters赋值
   employeevo.setWhereClause(whereClause.toString());
   if (bindCount > 0) {
     Object[] params = new Object[bindCount];
     parameters.copyInto(params);
     employeevo.setWhereClauseParams(params);
   }
 
   //进行查询
   employeevo.executeQuery();

}

 

OAF_开发系列13_实现OAF通过Vector动态查询设置(案例)三、测试运行


Test1. 打开测试页面

OAF_开发系列13_实现OAF通过Vector动态查询设置(案例) 

Test2. 进行查询,资料顺利查出

OAF_开发系列13_实现OAF通过Vector动态查询设置(案例)

 

Thanks and Regards

参考:http://shaofeng.blog.51cto.com/3392077/655682

OAF_开发系列13_实现OAF通过Vector动态查询设置(案例)

ERP技术讨论群: 288307890
技术交流,技术讨论,欢迎加入
Technology Blog Created By Oracle ERP - 鲍新建
上一篇:OAF_开发系列11_实现OAF通过DataBoundValues动态显示表列的左右对齐


下一篇:Docker--简介、安装