OAF―怎样设置动态的查询

在OAF的开发中,动态查询是避免不了的,就是根据用户输入的条件来查询,当然OAF中有很多方面的方法,但是有一种方法是用的最为普遍的.

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

am.invokeMethod("initDetails", parameters);

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

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

2.在AM的java文件中写一个initDetails方法函数,来调用VO中的方法.如:initQuery(String XXXX);

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

这段代码直接运行的话要原来的基础上要import一个类:

import java.util.Vector

Initialize and execute the query
public void initQuery(String name, String onHold, String number)
{

StringBuffer whereClause = new StringBuffer(100);
Vector parameters = new Vector(3);
int clauseCount = 0;
int bindCount = 0;

setWhereClauseParams(null); // Always reset

   if ((name != null) && (!("".equals(name.trim()))))
   {
     whereClause.append(" NAME like :");
     whereClause.append(++bindCount);
     parameters.addElement(name + "%");
     clauseCount++;
   }
   if ((number != null) && (!(""Equals(number.trim()))))
   {
   
     Number supplierId = null;
   
     // SUPPLIER_ID is a NUMBER; datatypes should always
     // match, and the parameter passed to this method is a
     // String.
     try
     {
       supplierId = new Number(number);
     } 
     catch(Exception e) {}
   
     if (clauseCount > 0)
     {
       whereClause.append(" AND "); 
     }
   
     whereClause.append(" SUPPLIER_ID = :");
     whereClause.append(++bindCount);
     parameters.addElement(supplierId);
     clauseCount++;
   }
   if ((onHold != null) && (!(""Equals(onHold.trim()))))
   {
     if (clauseCount > 0)
     {
       whereClause.append(" AND "); 
     }
   
     whereClause.append(" ON_HOLD_FLAG = :");
     whereClause.append(++bindCount);
     parameters.addElement("Y"); 
     clauseCount++;
   }
   setWhereClause(whereClause.toString());
   if (bindCount > 0) 
   {
     Object[] params = new Object[bindCount];
   
     // the copyInto() is 1.1.8 compliant which, as of 4/02/03, is required by ARU
   
     parameters.copyInto(params); 
     setWhereClauseParams(params);
  }
   
  executeQuery();
 } // end initQuery( )

Genterate an Application Module Interface

If you want to generate an application module interface

so you can invoke typed methods directly

(with compile-time checking) instead of calling

invokeMethod(), you must first create the methods

that you want to expose to the client. Then:

  1. In the JDeveloper Navigator, select the application module
  2. that you just created, right-click and select Edit <appmodule_name>....
  3. In the Application Module Wizard, select Client Methods.
  4. Select the methods you want to be able to invoke remotely in the
  5. Available list and shuttle them to the Selected list.
  6. Select OK to create your interface.

你可能感兴趣的:(职场,动态查询,休闲,oaf)