الثلاثاء، 7 أبريل 2020

ADF Memory Scopes

When it comes to variables, we need to use them carefully as wrong usage may lead to unnecessary memory consumption and confusion if the associated memory is not released on time. Example, once an object with application scope is assigned a value, it retains the value for the entire application irrespective of user session.
So, lets see how objects with different scopes behave and used.
Different Scopes:
  1. Application Scope: Used to store information which are session independent. Static information which are the same for all users and are available for the entire application.
  2. Session Scope: Information like user related data which need to be available from the session start to session end are stored in the session scope.
  3. PageFlow Scope: Available for the duration of a task flow and exit while exiting the task flow.
  4. View Scope: Stores object for the current view and releases while navigating to a different view or there is a change in view id.
  5. Request Scope: Stored object is available for the current HTTP request and exits when a response is sent back to the client.
We will go through an example where we can see how objects with different scopes work.
Hands-on:
Let’s start with creating two pages on an unbounded taskflow and a bounded taskflow with two more pages.
ms1
The first jspx is created with an input text and a button which sets the input value to different scopes. It has also another button to navigate to another jspx in the same unbounded task flow.
ms2
From the second page, we will invoke a bounded taskflow. The bounded taskflow has two pages. All the pages have the same items which display the information stored in different memory scopes.
ms2

Lets apply a user-input in the text input field of testScopePG and hit ‘SetApplicationScope’. Fields with all the scopes(Including View and Request) will be populated with the same value.
ms14
The values for the input items are:
#{sessionScope.KEY}
#{viewScope.KEY}
#{applicationScope.KEY}
#{pageFlowScope.KEY}
#{requestScope.KEY}

ms13
Now, click ‘NavigatetoPG1’ which will navigate to testScopePG1. Here we could see that Viw and Request scope fields are empty.
ms10
View attribute is null as it retains as long as the view(viewid for page) doesn’t change.Request attribute is null as the NavigatetoPG1 event resulted in a new http request.
Lets call the taskflow by clicking ‘TF Call’. We see that the PageFlow attribute became null. Its because there is a change in workflow as we navigated from the inbounded taskflow to the bounded taskflow.
ms11
Throughout the testing so far, we see that Application and Session scopes are retained.
Now, lets close our browser and click on the ‘Target URL’ link for testScopePG on the log as shown below and see that the session is now gone and its just the application scope that is retained.
ms16
ms17
Source Code for the managed bean:
In the above example, the below code is written to set the attributes at different scopes.
ms6
Below is the code for ‘SetApplicationScope_action()’ associated with ‘SetApplicationScope’ button.ms7

ليست هناك تعليقات:

إرسال تعليق

ADF: Programmatic View Object Using Ref Cursor.

ADF: Programmatic View Object Using Ref Cursor. Posted by:  Manish Pandey   April 25, 2013   in  ADF   Leave a comment   3758 Views Sometime...