壹佰网|ERP100 - 企业信息化知识门户

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2280|回复: 0

[OAF] [抛砖引玉]OAF数据的读与写-part1:数据的读取

  [复制链接]
发表于 2008/9/26 00:08:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622  。

您需要 登录 才可以下载或查看,没有帐号?注册

x
**********************************
很久没看到新帖子里,所以抛砖引玉,大家讨论讨论。
我比较习惯于读英文,所以后面的就没有翻译,大家有问题可以跟帖讨论。
前面中文写的也不好,大家见谅。


知识是很基础的知识,但大家要理解了OAF里的MVC后,看起来才好。谢谢!
**********************************




假定你已经指定了相应的数据源对映(data source binding)OAF会自动地从Model读取数据从而显示到UI上,也会把用户在UI上输入的数据写回到Model里。而你不用写任何编码(当然除非你要验证对应的EO)。

读取MODEL的数据
简单地,OAF每显示一个页面时,每个Web Bean对应的VO变量都需要调用该VO的行(Row)get<AttributeName>方法
考虑个由”Supplier”表构成SuppliersVO的页面的例子。尽管在VO里有个“设计的”临时变量(”OnHoldDisplay”)并不存在于EO变量里, 其他的SuppliersVO变量一一对映到SupplierEOImpl的变量
下图为当执行查询时OAFModel里读取数据的过程
read_data_flow.gif




1. 用户点击搜索区域的”Go”,会弹出Suppliers表的搜索数据
2. 该搜索区的Controller靠调用页根AM的搜索方法来处理用户的Button Press事件。由此来指定用SuppliersVOImpl这个类来进行查询
3. executeQuery这个方法里,SuppliersVOImpl直接进行数据库的SQL Select查询
4. 对于返回的结果集每一行,VO初始化了一个SupplierEOImpl实体,并用查询结果充当它的变量值。
注:EO的变量实际上并不储存在VO中。他们存在于EO,在使用时被VO取得。“设计的”(意思是这些值仅仅从SQL语句得到,和EO并无关系)或“临时的”VO变量储存在SuppliersVORowImpl对象里。
5. 在页面显示过程中(查询处理完成后),OAF为每个WebBean调用相应的与之绑定的数据行的get<AttributeName>方法
6. SuppliersVORowImpl中的get<AttributeName>方法再调用对应的SupplierEOImpl中的get<AttributeName>方法。对于“设计的”OnHoldDisplay变量,VO的行从它自己的缓存中取值。

Programatically implementation of Reading Data Model
***********************************************
Add an initQuery( ) Method to Your VOImpl (EmployeeFullVOImpl) Class

This method should take an employeeId parameter, set the WHERE clause to EMPLOYEE_ID = :1, bind the employeeId parameter to the WHERE clause, and execute the query (in effect, the view object should be capable of preparing to query and querying itself). Note: Pay attention to the import/use of the oracle.jbo.domain.Number. Whenever you instantiate a Number, you should import this class. If you forget to do this, you may encounter a runtime error complaining about java.lang.Number (the assumed class) being abstract, or you may get class cast exception errors.

import oracle.jbo.domain.Number;
import oracle.apps.fnd.framework.OAException;
...



public void initQuery(String employeeNumber)


{


if ((employeeNumber != null) &&


(!("".equals(employeeNumber.trim()))))


{



// Do the following conversion for type consistency.


Number empNum = null;




try


{


empNum = new Number(employeeNumber);


}


catch(Exception e)


{


throw new OAException("AK", "FWK_TBX_INVALID_EMP_NUMBER");


}


setWhereClause("EMPLOYEE_ID = :1");


setWhereClauseParams(null); // Always reset


setWhereClauseParam(0, empNum);


executeQuery();




}


} // end initQuery()



Add an initDetails( ) Method to Your AMImpl (EmployeeAMImpl) Class

You will invoke this method from your UI controller (per the OA Framework coding standards, you should interact only with the OAApplicationModule interface in your controller; you should not interact directly with view objects). This method delegates to the initQuery() method that you just created on the EmployeeFullVOImpl class. Note the import/use of the oracle.apps.fnd.framework.OAException and oracle.apps.fnd.common.MessageToken classes.

import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.common.MessageToken;
...



/*****************************************************************************


* Initializes the detail employee query.


*****************************************************************************


*/


public void initDetails(String employeeNumber)


{


EmployeeFullVOImpl vo = getEmployeeFullVO1();


if (vo == null)


{


MessageToken[] errTokens = { new MessageToken("OBJECT_NAME", "EmployeeFullVO1")};


throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", errTokens);


}


vo.initQuery(employeeNumber);




} // end initDetails()



Add Controller Logic to Initalize the Employee Query When the Page Renders

To automatically query the underlying EmployeeFullVO view object when the EmpDetailsPG renders, add the following code to the EmployeeDetailsCO.processRequest() method. Note that you are referencing the employeeNumber parameter that you add to the URL when the user selects the Employee Name link.

import java.io.Serializable;
import oracle.apps.fnd.framework.OAApplicationModule;
...



public void processRequest(OAPageContext pageContext, OAWebBean webBean)


{


// Always call this first.


super.processRequest(pageContext, webBean);




// Get the employeeNumber parameter from the URL


String employeeNumber = pageContext.getParameter("employeeNumber");




// Now we want to initialize the query for our single employee


// with all of its details.


OAApplicationModule am = pageContext.getApplicationModule(webBean);


Serializable[] parameters = { employeeNumber };


am.invokeMethod("initDetails", parameters);



}

**************************

[ 本帖最后由 iamji 于 2008-9-26 00:11 编辑 ]

评分

参与人数 2努力值 +10 收起 理由
Michael + 5 非常清楚的解释了Data Source Binding的问题 ...
纵横四海 + 5 支持原创!支持楼主!

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/29 07:28 , Processed in 0.020365 second(s), 19 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表