简体   繁体   English

为什么不应该通过JSF框架管理实体bean?

[英]why shouldn't entity bean be managed by JSF framework?

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. 我读了一些帖子听到(特别是BalusC帖子)和googled的原因(不深)但我找不到为什么不应该使用实体bean作为托管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.) (我正在学习“Pro JSF和HTML5”,在本书中,实体bean被用作托管bean。)

Separation of concerns. 关注点分离。

Normally, enterprise applications are developed and deployed as EARs instead of WARs. 通常,企业应用程序是作为EAR而不是WAR开发和部署的。 A typical EAR project consists of an EJB subproject as "back-end" and a WAR subproject as "front-end". 典型的EAR项目包含EJB子项目作为“后端”,WAR子项目作为“前端”。 The EJB subproject contains all JPA entities and EJB services. EJB子项目包含所有JPA实体和EJB服务。 The WAR subproject contains all JSF managed beans and views (and what not closely related to JSF such as converters, validators, phase listeners, etc). WAR子项目包含所有JSF托管bean和视图(以及与JSF没有密切关系的内容,如转换器,验证器,阶段监听器等)。

A good EJB subproject may not have any dependency on JSF. 一个好的EJB子项目可能不依赖于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. 这使得它可以重用于不同的前端,例如Spring MVC,JAX-RS,Struts2,普通的JSP / Servlet,甚至是面向桌面的Swing应用程序。 This also means that no one of your JPA entities and EJB services should have any javax.faces.* import/dependency in the class. 这也意味着您的JPA实体和EJB服务中没有一个应该在类中具有任何javax.faces.* import / dependency。 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. 举例来说,JPA实体或EJB服务中的FacesContext是令人震惊的,因为它不一定存在于其他前端。

The "Pro JSF and HTML5" concentrates on simple WAR projects. “Pro JSF和HTML5”专注于简单的WAR项目。 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. 其中“好”是为了展示可能性和/或保持示例“简单”,但这对于初学者一旦成长为开发企业应用程序实际上会产生误导,如果本书不涉及设计问题,则更是如此。详情。

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM