您的位置:首页 > 产品设计 > UI/UE

Scope的几种分类-Session,request,pageflow,view,backingbean

2011-11-03 17:18 309 查看
applicationScope: The object is available for the duration of the application.

sessionScope: The object is available for the duration of the session.

requestScope: The object is available for the duration between HTTP requests until a response is sent back to the client.

In addition to the standard JSF scopes, ADF Faces provides the following scopes:

pageFlowScope: The object is available as long as the user continues navigating from one page to another. If the user opens a new browser window and begins

navigating, that series of windows will have their own pageFlowScope scope.

backingBeanScope: This is used for managed beans for page fragments and declarative components only. The object is available for the duration between HTTP requests until a response is sent back to the client. This is needed because there may
be more than one page fragment or declarative component on a page,and to avoid collisions between values, any values must be kept in separate scope instances. Therefore, any managed bean for a page fragment or declarative component must use backingBeanScope
scope.

viewScope: The object is available until the ID for the current view changes. Use viewScope scope to hold values for a given page. While requestScope scope

can be used to store a value needed from one page to the next, anything stored in viewScope scope will be lost once the view ID changes.

在以往的应用开发过程中,后端的业务组件(Action/Service/Dao),可以被设置为几种作用域:request、session、application。我们不可能把与每次请求关系很强的一些信息(例如某个列表页面要列出来的数据集合)简单的放到session里面去,这就导致了每次请求之间的大部分数据是不可能共享的。使用JSF,我们实现了一种叫做view的作用域,在不同的请求之间共享信息。

新版的spring中提出了一个conversation作用于,也是介于request和session之间的一个作用于,和seam中的conversation应该差不多。

view作用域是生命周期介于request和session之间的一个作用范围。当一个Spring Bean(一般来说是Action层面的Bean)被标注作用域为view的时候,Spring会在需要用到这个Bean的时候创建之,然后,在当前页面没有发生整页的reload、跳转的情况下,这个bean一直存在。所谓整页reload、跳转说的就是我们普通的表单提交,URL GET请求。发生除此之外的其他请求(目前能想到的其实也就是一种:Ajax请求)的时候,前面创建出来的bean对象一直存在。

我们在一个列表页面加载的时候,使用一个view作用域的bean作为其action对象,于是加载完成后,要对列表中的某些行执行操作的时候,你都不需要再次去查询,因为整个对象集合都依然存在!

本质上讲,view作用域中的数据时被放在了session中。但是JSF实现了对于这写内容的管理方式,不需要使用人员关心。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: