Thursday 1 May 2014

How to get and set Values in SessionScope in ADF

Hello all,

During the development in ADF sometimes we need to define some values in the user session so that it can be used further in the session.

Suppose we need to put the name of the logged-in user in the session to use it further in the application. We can do so by using HttpSession as it is used in a web based java application.

We can access the session from the FacesContext in ADF Application. 
Here is the java code for doing so.

FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)
// false is passed in getSession method to get the already created session
// If true is passed then a new session will be created
context.getExternalContext().getSession(false);
// Here attribute and value are the name and value to the attribute that you want to set in the session.
session.setAttribute("Attribute", value);
// Here attribute is the attribute name whose value you want to fetch

session.getAttribute("Attribute");


No comments:

Post a Comment