JDeveloper使用EJB,JPA,JavaServer Faces技术开发Web应用程序实例

概要:在JDeveloper 11gR1中,使用EJB, JPA and JavaServer Faces技术开发一个Web应用程序。Data Model,使用EJB diagrammer, EJB 3.0 and Java Persistence API (JPA)创建。View Controller,一个JSF Page会被创建用来浏览编辑HR信息。实例中,还创建了一个task flow用来查询查询员工,该task flow会做为ADF region添加到JSF Page上。


1. Part1:使用EJB3.0创建数据模型
          可以使用EJB/JPA组件创建Web Application的Data Model。JDeveloper提供了wizards来创建EJB projects,实体,持久化单元,会话beans,消息驱动beans. Java Persistence API(JPA)提供了POJO持久化模型用来做面向对象的数据映射。
(1)创建一个新的Application和Projects
(2)创建持久化模型
使用EJB3.0实体beans创建Departments和Employees的持久化模型,该步完成后就会生成JPA实体。
(3)创建EJB Diagram
EJB Diagram可以可视化各种beans及其之间的关联关系。
(4)创建客户端应用程序使用的会话Bean
        Session Bean是一些具体的业务逻辑,例如查找employees和departments的记录,就可以做成会话beans。Client端通过Session Bean层与EJB通讯。好处是:(1)减少了用户直接访问EJB3.0实体时的network traffic引起的性能问题;(2)是Client与EJB的business objects解耦合,代码容易维护。
有两种类型的session bean:Stateless session bean和 stateful session bean。stateful session bean使用场合:用户登录权限切片控制,购物车等。
A stateful session bean maintains conversational state on behalf of the client. A conversational state is defined as the session bean field values plus all objects reachable from the session bean fields. Stateful session beans do not directly represent data in a persistent data store, but they access and update data on behalf of the client. The lifetime of a stateful session bean is typically that of its client.
        Stateless session beans are designed strictly to provide server-side behavior. They are anonymous because they contain no user-specific data. The EJB architecture provides ways for a single stateless session bean to serve the needs of many clients. All stateless session bean instances are equivalent when they are not involved in serving a client-invoked method. The term stateless means that it does not have any state information for a specific client. However, stateless session beans can have non-client specific state, for example, an open database connection.
        Use Container for a transaction being handled by the session facade and bean for managing user transaction explicitly through a programmatic process.
(5)使用EJB会话beans创建ADF Data Controls.

2. Part2:创建View Project
           Part1在EJB/JPA组件的基础上创建了Data Controls,下面创建JSF页面。
(1)为JavaServer Faces Page创建Global Layout
(2)将JSF Page绑定到Data Control
(3)运行测试页面
(4)增加新建/删除功能

3. Part3添加新的方法供UI使用
          使用EJB3.0注解技术为实体Beans添加新的Data Control方法,然后将该方法暴漏给task flow中的Web Page。
(1)修为Employees实体Bean的@NamedQuery,为其添加通过工资查询员工的getEmployeesFindBySal()方法
(2)创建有两个JSF页面的Bounded Task Flow
【注意】有两种类型的task flow.
          Unbounded task flow: A set of activities, control flow rules, and managed beans that interact to allow a user to complete a task. The unbounded task flow consists of all activities and control flows in an application, that are not included within a bounded task flow. 
          Bounded task flow: A specialized form of task flow that, in contrast to the unbounded task flow, has a single entry point (an entry point is a view activity that can be directly requested by a browser) and zero or more exit points. It contains its own set of private control flow rules, activities, and managed beans. A bounded task flow allows reuse, parameters, transaction management, reentry, and can render within an ADF region in a JSF page.
(3)将Task flow region添加到mainHR page
You can extract, configure, and package application functionality within a bounded task flow so that it can be added to other pages using an ADF region. ADF regions can be reused wherever needed, which means they are not dependent on a parent page.

(4)运行mainHr Page


4. Part4:Testing the Facade Inside and Outside the Java EE Container

Step 1: Add a New Method to the Entity and Expose it

Step 2: Run the Java Service outside the Java EE container

效果如下图所示:


参考

【1】http://docs.oracle.com/cd/E18941_01/tutorials/toc.htm

【2】http://st-curriculum.oracle.com/obe/jdev/obe11jdev/ps1/ejb/ejb.html

【3】http://blog.csdn.net/luyushuang/article/details/5885447

【4】http://hi.baidu.com/smilease/blog/item/798e42cbbfe7e4017f3e6fdb.html

【5】使用 EJB、JPA 和 JavaServer Faces 通过 JDeveloper 11g 构建 Web 应用程序

http://www.oracle.com/ocom/groups/public/@otn/documents/webcontent/229517_zhs.html

Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值