JSF 2.0 问题(faces-config)

发布于 2024-09-06 04:11:27 字数 238 浏览 2 评论 0 原文

JSF 1.0 中有 faces-config.xml,我们在其中输入有关托管 bean、依赖项和配置的信息。 。

我正在使用 JSF 2.0 开发一个示例项目 但是,由于我不知道注释,我需要在外部包含 face-config.xml 。请提供它的解决方案,因为在 JSF 2.0 中我们不需要包含它。其背后的原因是什么?我们如何将 bean 设置为托管 bean。什么是注解?它是如何使用的?

We have faces-config.xml in JSF 1.0 where we entry about managed-beans, dependencies & navigations etc.

I was developing a sample project using JSF 2.0. But, as I don't know annotation, I need to include face-config.xml externally. Please, provide the solution for it, as in JSF 2.0 we don't need to include it. What is reason behind it? How do we set a bean as managed-bean. What is annotation? How is it used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

末骤雨初歇 2024-09-13 04:11:27

(...) 在 JSF 2.0 中我们不需要包含它。其背后的原因是什么?

简而言之:易于开发。只是需要编写的代码更少——样板代码被删除,尽可能使用默认值,并且使用注释来减少对部署描述符的需求。

我们如何将 bean 设置为托管 bean。什么是注解?如何使用?

托管 Bean 使用 @ManagedBean 注释进行标识。 bean 的范围也可以使用注释来指定(@RequestScoped@SessionScoped@ApplicationScoped 等)。

因此,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>

在 JSF 2.0 中可以这样重写: 在

@ManagedBean
@SessionScoped
public class Foo {
    //...
}

Facelet 页面中这样引用:(

<h:inputText label="eMailID" id="emailId" 
value="#{foo.email}" size="20" required="true"/>

默认情况下,托管 bean 的名称将是带注释的类的名称,其中的第一个字母为类小写。)

另请参见

(...) in JSF 2.0 we don't need to include it. 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. What is annotation? How is it used?

Managed beans are identified using the @ManagedBean annotation. The scope of the bean is also specified using annotations (@RequestScoped, @SessionScoped, @ApplicationScoped, etc).

So the following in 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:

@ManagedBean
@SessionScoped
public class Foo {
    //...
}

And referred like this in a Facelet page:

<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.)

See also

八巷 2024-09-13 04:11:27

请参阅注释教程

对于 JSF,您可以执行类似的操作(使用 @ManagedBean 注释):

@ManagedBean
public class YourManagedBean {
    ...
}

See the annotations tutorial.

For JSF, you can do something like this (using the @ManagedBean annotation):

@ManagedBean
public class YourManagedBean {
    ...
}
呆° 2024-09-13 04:11:27

您可以像在 JSF 1.x 中那样在 JSF2 中使用 faces-config.xml。事实上,虽然注释通常可以用来代替 faces-config.xml 文件,但并非每个 JSF 功能都可以严格通过注释来使用,因此有时即使在 JSF2 中也需要 faces-config 文件。

然而,有一个小区别,那就是您应该更新 faces-config 文件中的 xml 模式版本引用,以反映随 JSF2 生效的模式更改。

You can employ a faces-config.xml in JSF2 exactly the same way you did in JSF 1.x. 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文