在JSF 2.0中使用@ViewScoped? [英] Use of @ViewScoped in JSF 2.0?

查看:93
本文介绍了在JSF 2.0中使用@ViewScoped?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用@ViewScoped在JSF 2.0中@ManagedBean下面使用/优点

How to use / advantages of using @ViewScoped below the @ManagedBean in JSF 2.0

推荐答案

@ManagedBean 只是声明某个bean由JSF管理(使其可用于表达式语言等)。

@ManagedBean just declares that a certain bean is managed by JSF (makes it available to expression language among others).

@ViewScoped 允许您声明bean将使用的特定范围。默认情况下(当您不知道时)指定任何范围)是 @RequestScoped ,这意味着您的bean将通过单个请求生存,然后将被销毁。其他范围是 @SessionScoped @ApplicationScoped 。第三方扩展引入了其他范围。

@ViewScoped lets you declare a specific scope the bean will live in. The default (when you don't specify any scope) is @RequestScoped, which means your bean will live through a single request and will then be destroyed. Other scopes are @SessionScoped and @ApplicationScoped. Third party extensions have introduced other scopes.

<$ c只要您将页面发回给自己,$ c> @ViewScoped 就会继续生效。 视图是Java EE中页面的另一个词,但页面范围在Java EE中已经具有其他含义。视图范围非常方便,因为它允许在您第一次访问页面时(通过非面部请求,通常是GET请求)初始化数据的模式,然后在您处理页面时保留数据,执行回发,AJAX请求等。

@ViewScoped will keep living as long as you post back a page to itself. A 'view' is another word for 'page' in Java EE, but page scope already meant something else in Java EE. The view scope is very convenient, since it allows the pattern of initializing data when you first access a page (via a non-faces request, which is typically a GET request) and then keep that data when you work on the page, doing postbacks, AJAX requests, etc.

当您使用JSF中的表与表中的组件进行交互时,范围是一个救星。也就是说,在JSF中,有一条规则,即用于呈现表的数据必须是回发后处理与您交互的组件时使用的EXACT SAME数据。使用视图范围这是微不足道的,但没有它它是相当棘手的。

The scope is a lifesaver when working with tables in JSF where you interact with components in the table. Namely, in JSF there is a rule that the data that was used to render the table must be the EXACT SAME data that is used after the postback when processing the components you interacted with. With the view scope this is trivial, but without it it's rather tricky.

这篇关于在JSF 2.0中使用@ViewScoped?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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