为什么在使用JSF Web应用程序时需要bean.xml? [英] Why do we need beans.xml while working with JSF web application?

查看:112
本文介绍了为什么在使用JSF Web应用程序时需要bean.xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在学习了一段时间的JSP和Servlet之后,我开始使用JSF进行Web开发.

I started web development using JSF, after studying JSP and Servlets for a while.

在创建JSF Web应用程序时,您总是(可能经常,但是我不确定是否总是)必须创建beans.xml,并且您无需在其中编写任何内容.但是,如果该文件不存在,那么JSF Web应用程序将无法工作.

When you create a JSF web application you always(may be often but I am not sure if it always or not) have to create beans.xml and you don't write anything in it. But, if that file doesn't exist the JSF web app will not work.

其背后的原因是什么?

为什么我们需要那个文件?

Why we need that file?

请详细解释.

推荐答案

添加到Micheal的答案中; CDI不仅由于注入支持而与JSF结合使用,还因为其与EL(表达式语言)一起使用的支持.这是JSF严重依赖的功能.

Adding to the answer of Micheal; CDI is not only useful in combination with JSF because of the injection support, but also because of its support to be used with EL (expression language). This is a feature JSF heavily depends upon.

事实上,CDI bean几乎可以完全替代JSF管理的bean,因此,您会发现许多使用它们的示例以及大量的JSF书籍来建议它们的使用.对于JSF应用,CDI bean具有例如具有以下优点:

In fact, CDI beans can almost entirely replace JSF managed beans and therefor you'll find lots of examples using them and a good amount of JSF books advising their use. For JSF applications CDI beans have e.g. the following advantages:

  1. 可以将较小的范围注入较大的范围.例如.可以将请求范围的GET参数注入到会话范围的Bean中.对于JSF托管的bean,这是不可能的.
  2. 可以利用对话范围;产生多个不同页面的作用域.

非常不幸的是,在JSF 2.0和2.1中,默认情况下CDI bean不支持极其方便的视图范围,尽管像Seam这样的扩展可以添加这些范围. (更新:在JSF 2.2中,有一个新的视图范围适用于CDI bean)

Very unfortunate is that in JSF 2.0 and 2.1 the extremely handy view scope is not supported by CDI beans by default, although extensions like Seam can add these. (update: in JSF 2.2 there's a new view scope that does work with CDI beans)

JSF受管Bean和CDI Bean之间的所有混淆都导致存在JSF规范问题,请参见 http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-976

All in all the confusion between JSF Managed beans and CDI beans is such that there's a JSF spec issue for this, see http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-976

这篇关于为什么在使用JSF Web应用程序时需要bean.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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