This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes how to access a session value on JSF page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "how to access a session value on JSF page?" Watch "how to access a session value on JSF page?" New topic
Author

how to access a session value on JSF page?

in.anurag Singh
Greenhorn

Joined: May 14, 2010
Posts: 25
Hi,

I am a newbie to JSF, and i am strucked up with a small problem.
I am wondering how can i set a value in a session from a bean or any other action method, and then retrieve it on any other JSF page.
In Struts , we have a simple option of setting session objects, but i am not able to find the same way in JSF.
Please give me the solution to this problem with the statements used to set the session from the bean or any other java class, and then retrieving the same value on any JSF page..

any help will be greatly appreciated..
Jagadeeswara Yaramala
Ranch Hand

Joined: Jul 28, 2010
Posts: 46
I think this is relatively easy in JSF.

Just make the backing bean to be session in faces-config.xml file..

Here is an example of how to do it.
Managed Bean example


I think, if the managed bean scope is made to be 'session' then you can access it from any JSF page in the session.

P.S: I am new to JSF !!

in.anurag Singh
Greenhorn

Joined: May 14, 2010
Posts: 25
i don't think that the link is what i am looking for..
i am searching for something which is like..



and



how can we do the same in jsf , when we have to retrieve some value,collections on the jsf page..
Jagadeeswara Yaramala
Ranch Hand

Joined: Jul 28, 2010
Posts: 46
May be this URL helps...
FacesContext session


Once you get the session object, you can use setAttribute and getAttribute methods.

However, JSF provides much easier way to manage session data, if you use the session backing beans properly.

Your case may be that you want to store computed value/object in the session.
in.anurag Singh
Greenhorn

Joined: May 14, 2010
Posts: 25
The link was helpful but it is not explaining the way of retrieving session attributes on JSF web page..
how can i retrieve the session on the jsf page
Jagadeeswara Yaramala
Ranch Hand

Joined: Jul 28, 2010
Posts: 46
You can get a request parameter id using the expression:

<h: outputText value="#{param['id']}" />
<h: outputText value="#{sessionScope['id']}" />
param—An immutable Map of the request parameters for this request, keyed by parameter name. Only the first value for each parameter name is included.
sessionScope—A Map of the session attributes for this request, keyed by attribute name.
Section 5.3.1.2 of the JSF 1.0 specification defines the objects that must be resolved by the variable resolver.


Reference: StackOverflow Q&A

However, session and request parameters are handled in Struts and JSF differs. JSF has backing beans for session, request and application objects. If JSF pages explicitly get and set session parameters, then the JSF backing beans are not used effectively and is under utilization of JSF architecture.

Hope this helps.
anbuselvan angamuthu
Greenhorn

Joined: Jul 31, 2010
Posts: 2
if you give scope variable as session. you can access the session in the following way

FacesContext facesContext = FacesContext.getCurrentInstance();
Map<String,Object> map =facesContext.getExternalContext().getSessionMap();
 
 
subject: how to access a session value on JSF page?
 
Similar Threads
"Correct" way to detect timeout in form handling?
JSF Variable State: Odd Behavior
[Resolved] Services as Managed Beans
how to pass paramenter from one bean to another bean without using session in jsf 2.0?
How to set the value of bean property (type java.util.Set) form JSF page