[英]JSF 2.0 Problem (faces-config)
We have faces-config.xml
in JSF 1.0 where we entry about managed-beans, dependencies & navigations etc. 在JSF 1.0中,我们有
faces-config.xml
,其中输入了有关托管bean,依赖项和导航等信息。
I was developing a sample project using JSF 2.0. 我正在使用JSF 2.0开发一个示例项目。 But, as I don't know annotation, I need to include
face-config.xml
externally. 但是,由于我不知道注释,因此需要在外部包含
face-config.xml
。 Please, provide the solution for it, as in JSF 2.0 we don't need to include it. 请为它提供解决方案,因为在JSF 2.0中,我们不需要包含它。 What is reason behind it?
背后的原因是什么? How do we set a bean as managed-bean.
我们如何将一个bean设置为managed-bean。 What is annotation?
什么是注解? How is it used?
如何使用?
(...) in JSF 2.0 we don't need to include it.
(...)在JSF 2.0中,我们不需要包含它。 What is reason behind it?
背后的原因是什么?
In three words: ease of development. 用三个词来说:易于发展。 There is just less code to write -- boilerplate code is removed, defaults are used whenever possible, and annotations are used to reduce the need for deployment descriptors.
编写的代码更少了-删除了样板代码,在可能的情况下使用默认值,并使用注释来减少对部署描述符的需求。
How do we set a bean as managed-bean.
我们如何将一个bean设置为managed-bean。 What is annotation?
什么是注解? How is it used?
如何使用?
Managed beans are identified using the @ManagedBean
annotation. 使用
@ManagedBean
批注标识托管bean。 The scope of the bean is also specified using annotations ( @RequestScoped
, @SessionScoped
, @ApplicationScoped
, etc). 豆的范围也使用注释(指定
@RequestScoped
, @SessionScoped
, @ApplicationScoped
等)。
So the following in JSF 1.0: 因此,JSF 1.0中的以下内容:
<managed-bean>
<managed-bean-name>foo</managed-bean-name>
<managed-bean-class>com.foo.Foo</managed-bean-class>
<managed-bean-scope>session</managed-bean>
</managed-bean>
Can be rewritten as such in JSF 2.0: 可以在JSF 2.0中这样重写:
@ManagedBean
@SessionScoped
public class Foo {
//...
}
And referred like this in a Facelet page: 并在Facelet页面中这样引用:
<h:inputText label="eMailID" id="emailId"
value="#{foo.email}" size="20" required="true"/>
(By default, the name of the managed bean will be the name of the annotated class, with the first letter of the class in lowercase.) (默认情况下,托管bean的名称将是带注释的类的名称,该类的首字母小写。)
See the annotations tutorial . 请参阅注释教程 。
For JSF, you can do something like this (using the @ManagedBean
annotation): 对于JSF,您可以执行以下操作(使用
@ManagedBean
批注):
@ManagedBean
public class YourManagedBean {
...
}
You can employ a faces-config.xml in JSF2 exactly the same way you did in JSF 1.x. 您可以与在JSF 1.x中完全一样地在JSF2中使用faces-config.xml。 In fact, although annotations can often be used in place of a faces-config.xml file, not every JSF feature is available strictly through annotations, so sometimes you need a faces-config file even in JSF2.
实际上,尽管通常可以使用注释来代替faces-config.xml文件,但是并非每个JSF功能都可以通过注释严格使用,因此有时即使在JSF2中,也需要一个faces-config文件。
There is one small difference, however, and that is that you should update the xml schema version reference in your faces-config file to reflect schema changes that came into effect with JSF2. 但是,有一个小差异,那就是您应该更新faces-config文件中的xml模式版本引用,以反映JSF2生效的模式更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.