了解被管理的bean /后备bean [英] Understanding managed beans/backing beans

查看:100
本文介绍了了解被管理的bean /后备bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Java EE 6,我正在努力掌握它的整体形象。我正在阅读关于JSF和如何添加组件。我正在从组件设置/读取值到具有@ManagedBean注释的bean。



我有一些麻烦,正确理解。什么是Managedbeans?它只是只是保持组件状态的对象吗?他们也可以有其他方法吗? EJB适合哪里?托管bean是否在EJB上调用方法?

解决方案


什么是Managedbeans?是只是对象的
的组件的状态?


一个JSF托管的bean就像任何其他Java bean除了由JSF管理。换句话说,它是一个由JSF根据需要创建和销毁的bean。



Hortsman Core JSF 2 图书状态。



JSF实现执行以下操作:


  1. 根据需要创建和丢弃bean(因此,术语managed
    beans)

  2. 显示网页时读取bean属性

  3. 在表单发布时设置bean属性




他们可以其他方法也是如此?


是的,他们可以有尽可能多的方法,你可能想要的。但是,(应该)理想地喜欢让您的托管bean尽可能精简。例如,它可能具有搜索方法,但您不应该在此方法中实际搜索,但是这种搜索方法的唯一目的应该是将任务委托给业务层(可能或不可能基于EJB)。
我其他单词 no heavy lifting


EJB适合在哪里?


EJB是您的业务层,他们有大二头肌,并做所有的重大举措。由于引入了EJB3 JPA,而且也是EJB的一部分。 JPA是持久层。除了JPA之外的所有EJB都在EJB容器内部运行。所有Java EE投诉服务器提供这些。在一个典型的3层架构(现在这些天,大多数是3,但是3层次更容易解释),JSF是你的Web层,EJB是你的业务层和JPA也是EJB规范的一部分,但不需要EJB容器是您的ORM或Persistence层。
不要担心word容器太多,你会很快习惯它,很少你会担心它。如果您使用的是Java EE服务器,那么这些都是为您设置的。


托管的bean是否在EJB上调用方法? >

如上所述已经有了,所有这一切都很重要,但是并不是必须使用EJB与JSF,你可以使用任何其他框架,例如春天甚至可以写简单的pojos,但这是另一个讨论区域。


I am learning Java EE 6 and I am trying to grasp the overall image of it. I am reading about JSF and how adding components. I am setting/reading values from the components to a bean which has the @ManagedBean annotation.

I have some trouble understanding it properly. What is Managedbeans? Is it just just objects that holds the state of the components? And they can have other methods as well? Where does the EJBs fit in? Does the managed beans invoked methods on the EJBs?

解决方案

What is Managedbeans? Is it just just objects that holds the state of the components?

A JSF Managed bean is like any other Java bean except that if it managed by JSF. In other words it is a bean that is created and destroyed by JSF as needed.

Hortsman Core JSF 2 book states.

The JSF implementation does the following:

  1. Creates and discards beans as needed (hence the term "managed beans")
  2. Reads bean properties when displaying a web page
  3. Sets bean properties when a form is posted

And they can have other methods as well?

Yes they can have as many methods as you may want.However you would (and should) ideally like to have your managed bean as lean as possible.For example it might have a search method but you should not be doing actually search inside this method but this search methods sole purpose should be to delegate the task to the business layer (which may or may not be EJB based) .
I other words no heavy lifting .

Where does the EJBs fit in?

EJB is your Business tier , they have big biceps and do all the heavy lifting. Since EJB3 JPA was introduced and that is also part of EJB. JPA however is the persistence tier. All EJBs except for JPA run in inside an EJB container. All Java EE complaint server provide these .

In a typical 3 tier architecture (these days however it is mostly more than 3 but 3 tiered is easier to explain. JSF is your Web tier , EJBs are your business tier and JPA which is also part of EJB specification but does not need EJB container is your ORM or Persistence tier. Do not worry about word container too much you will get used to it quickly and rarely you will have to worry about it. If you are using a Java EE server it's all setup for you.

Does the managed beans invoked methods on the EJBs?

Yes as explained above already . All the heavy lifting here. However it is not mandatory to use EJB with JSF. You could use any other framework e.g Spring or could even write simple pojos but thats an other area of discussion.

这篇关于了解被管理的bean /后备bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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