Wednesday, February 11, 2009

11G : Scopes

ADF supports all the usual scope options as in JSF like none, requestScope, session scope and application scope. Along with these scoping options ADF supports one additional highly useful scope option that is, pageFlowScope. Let's talk about these options one by one in brief:
Let's take an usecase to understand it better. Say, there is a a page 'pageA' in your application having a selectOneChoice and a submit button. On clicking the submit button it navigates you to 'pageB'. There is a bean method assoicated with the selectOneChoiceList's value change listener. this method is simply storing the selected value of the list to a bean property.


Fig: Scopes in ADF

1. none: So, with none scope, on changing the the value in the list, the associated bean will be instantiated and the associaed listner method will be called. As soon as the control returns from the bean method the bean will be destroyed. In other words, you cannot access the bean property value after that even on the same page.


2. requestScope: if the bean scope is requestScope then the value stored in the bean property will be accessible even on the pageB. you can simply access it at #{requestScope.yourBean.yourPropertyName}. This bean will be destroyed as soon as you submit another request by say clicking back button to navigate to pageA or by clicking a submit button to do some other action which generates another request to the server.


3. pageFlowScope: This scope is an introduction of ADF. In ADF you can group some pages (called activity) in a logical unit called TaskFlow (more specifically a bounded task flow in this case). Say you have two more pages pageC and pageD and you can navigate from pageA to pageB to pageC to pageD using some next button on each page. Now, suppose you have created a bounded task flow using pageA, pageB and pageC. So, if your bean is of pageFlowScope then after selecting a value in list at pageA if you navigate till pageC, you can still access the bean's property. It persists within the taskflow boundries. But, if you navigate to pageD then the bean will be destriyed. pageFlowScope is kinda more broader than requestScope and smaller than a session scope. For most of the scenarios in ADF you create a bounded task flow to implement a business use case. So, in way pageFlowScope makes more sense than a session scope. Ofcourse, session will be required in cases where you need to persis the values out of a taskflow boundry. You can access it using an EL expression like #{pageFlowScope.YourBean.yourPropertyName}.


4. sessionScope: Continuing with the same example, the bean once instantiated will persist till the entire user session. This session usually persists till a user is logged in. Usually, web servers are configured for a session time out property which makes the session invalid after the specified period of time. So, the bean's property can be access anywhere for that session. Usually, in real life scenarios information related to user like its profile are set in to the sessions.


5. applicationScope: As the name suggests this scope persists as long as the application is running. Ususally, application scope parameters are initialized at the time of application start-up (web server start). Generally, some all time needed resources are initialized using applicationScope which are required all the time and are independent of any specific role or responsibility.

6.View Scope: It Stores objects uaed by a Single Page and retains the objects as long as the user continues to interect with the page, and then automaticaly releases them when the user leaves the page.

7. PageFlow Scope : It makes it easier to pass values from one page to another within a taskflow. This Scopes means that the bean is available for a set of pages in the current taskflow

8. BackingBean Scopes:  It is uased for managed beans for page fragements and declarative components only