What is difference between JavaBean and ManagedBean

被刻印的时光 ゝ 提交于 2020-06-09 12:30:06

问题


I am reading What components are MVC in JSF MVC framework?

In the big architectural picture, your own JSF code is the V:

M - Business domain/Service layer (e.g. EJB/JPA/DAO)
V - Your JSF code
C - FacesServlet

In the developer picture, the architectural V is in turn dividable as below:

M - Entity
V - Facelets/JSP page
C - Managed bean

On the upper case, the JavaBean is a model.

But on the lower case, the Managed bean becomes a controller?

They are not the same thing? What are the difference?


回答1:


Short answer : 'Managed Bean' is a legacy short name for JSF managed bean. It's a Java Bean managed by JSF.

Long one :

A bean is typically a POJO (plain old java object) managed by a container.

Managed means here that the creation / destruction, the number of instances, their scope and the invocation of some specific method are handled by the container.

Containers are generally provided by the underlying server. In Java EE you have different container (CDI, EJB, Web, etc...)

JSF Managed Bean are bean managed by JSF container, EJB are managed by EJB Container, Servlet / filters by the servlet container, JPA entities by the EntityManager, etc.

For example, on a tomcat server, you have only web (servlet) container and not EJB one. If you use JSF (you must provide associated dependency) you will have managed beans as well.



来源:https://stackoverflow.com/questions/16978886/what-is-difference-between-javabean-and-managedbean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!