为什么不应该通过JSF框架来管理实体bean? [英] why shouldn't entity bean be managed by JSF framework?

查看:77
本文介绍了为什么不应该通过JSF框架来管理实体bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了一些帖子(特别是BalusC帖子),并出于某种原因(不很深)而在Google上搜索,但是我找不到为什么不应该将实体bean用作托管bean的原因.什么原因? (我从"Pro JSF and HTML5"中学习,在本书中,实体Bean被用作托管Bean.)

I read some post hear (specially BalusC post) and googled for the reason (not deep) but i couldn't find why shouldn't use entity bean as a managed bean. what's the reason? (I'm learning from "Pro JSF and HTML5" and in this book, entity bean is used as a managed bean.)

推荐答案

关注点分离.

通常,企业应用程序是作为EAR(而不是WAR)开发和部署的.典型的EAR项目由EJB子项目(作为后端")和WAR子项目(作为前端")组成. EJB子项目包含所有JPA实体和EJB服务. WAR子项目包含所有JSF托管的bean和视图(以及与JSF不紧密相关的内容,例如转换器,验证器,相位侦听器等).

Normally, enterprise applications are developed and deployed as EARs instead of WARs. A typical EAR project consists of an EJB subproject as "back-end" and a WAR subproject as "front-end". The EJB subproject contains all JPA entities and EJB services. The WAR subproject contains all JSF managed beans and views (and what not closely related to JSF such as converters, validators, phase listeners, etc).

一个好的EJB子项目可能对JSF没有任何依赖性.这使得它可用于不同的前端,例如Spring MVC,JAX-RS,Struts2,纯JSP/Servlet或面向桌面的Swing应用程序.这也意味着您的JPA实体和EJB服务中的没有人应该在该类中没有任何javax.faces.*导入/依赖项.例如,在JPA实体或EJB服务内部使用FacesContext表示警告,因为在其他前端中不一定存在这种情况.

A good EJB subproject may not have any dependency on JSF. This makes it reusable for different front-ends, such as Spring MVC, JAX-RS, Struts2, plain JSP/Servlet or even a desktop oriented Swing application. This also means that no one of your JPA entities and EJB services should have any javax.faces.* import/dependency in the class. Having for example a FacesContext at hands inside a JPA entity or EJB service is alarming as that doesn't necessarily exist in other front-ends.

"Pro JSF和HTML5"专注于简单的WAR项目.在这里,为了展示可能性和/或使示例保持简单"是可以的",但是一旦初学者开始开发企业应用程序,这实际上就误导了初学者,如果本书没有涵盖设计中的设计问题,那就更是如此.细节.

The "Pro JSF and HTML5" concentrates on simple WAR projects. Therein that's "okay" in order to show the possibilities and/or to keep the examples "simple", but that's actually misleading to starters once they grow into developing enterprise applications, the more so if the book doesn't cover the design concern in detail.

  • JSF Service Layer
  • Packaging EJB in JavaEE 6 WAR vs EAR - related answer from my colleague Arjan.

这篇关于为什么不应该通过JSF框架来管理实体bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆