why shouldn't entity bean be managed by JSF framework?
Asked Answered
H

1

1

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.)

Homerhomere answered 21/8, 2014 at 16:28 Comment(0)
A
3

Separation of concerns.

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).

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.

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.

See also:

Aquiculture answered 21/8, 2014 at 17:20 Comment(3)
Thank you. it is a perfect answer. can you recommend a good book? (I'm beginner that want to be expert in JavaEE and JSF) and can you tell me what web server to choose, GlassFish or TomEE or something else?Homerhomere
You're welcome. As to books, the one you've at hands is good. Then there's "Beginning Java EE 7 in GlassFish". As to servers, I would personally recommend WildFly. TomEE is also okay. But definitely not GlassFish (anymore). It isn't actively maintained anymore since Oracle stopped commercial support on it. For what's worth, I'm currently for my blog writing a JSF 2.2 tutorial with WildFly. Might appear in some time.Aquiculture
Thank you, was big help.Homerhomere

© 2022 - 2024 — McMap. All rights reserved.