了解托管 Bean/支持 Bean
我正在学习 Java EE 6,我正在尝试掌握它的整体形象。我正在阅读有关 JSF 以及如何添加组件的内容。我正在将组件中的值设置/读取到具有 @ManagedBean 注释的 bean。
我在正确理解它时遇到一些困难。什么是托管bean?仅仅是保存组件状态的对象吗?他们还可以有其他方法吗? EJB 适用于哪里?托管 bean 是否调用 EJB 上的方法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JSF 托管 bean 与任何其他 Java bean 类似,只不过它由 JSF 管理。换句话说,它是一个由 JSF 根据需要创建和销毁的 bean。
Hortsman Core JSF 2 书中指出。
JSF 实现执行以下操作:
beans”)
是的,它们可以有您想要的尽可能多的方法。但是,理想情况下您会(并且应该)希望托管 bean 尽可能精简。例如,它可能有一个搜索方法,但您不应该在该方法内进行实际搜索但这种搜索方法的唯一目的应该是将任务委托给业务层(可能是也可能不是基于 EJB 的)。
换句话说,没有繁重的工作。
EJB 是您的业务层,它们拥有强大的二头肌并承担所有繁重的工作。由于 EJB3 JPA 被引入,它也是 EJB 的一部分。然而,JPA 是持久层。除 JPA 之外的所有 EJB 都在 EJB 容器内运行。所有 Java EE 兼容服务器都提供这些。
在典型的 3 层架构中(目前大多超过 3 层,但 3 层更容易解释。JSF 是您的 Web 层,EJB 是您的业务层,JPA 也是 EJB 规范的一部分,但不需要 EJB 容器是您的 ORM 或持久层。
不要太担心单词容器,您很快就会习惯它,并且很少需要担心它。如果您使用的是 Java EE 服务器,那么一切都已为您做好了设置。
是的,如上所述。所有繁重的工作都在这里。然而,将 EJB 与 JSF 一起使用并不是强制性的。您可以使用任何其他框架,例如 Spring,甚至可以编写简单的 pojo,但这是另一个讨论领域。
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:
beans”)
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 .
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.
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.
通过此链接 JSF - 托管 Bean
通过此链接为网页创建和使用支持 Bean
From this link JSF - Managed Beans
From this link Creating and Using a Backing Bean for a Web Page