File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How do I read a session variable inside a Managed Bean? 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 do I read a session variable inside a Managed Bean?" Watch "How do I read a session variable inside a Managed Bean?" New topic
Author

How do I read a session variable inside a Managed Bean?

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
My ManagedBean that does a database acccess has a PreparedStatement that will do a query based on the userID that's in the session scope.

In the managed bean, I have something like this:

"SELECT * FROM USERS WHERE USR_ID = ?", but the usr_ID is actually in a session variable.

I can't figure out how to get at the session (scope) variable from within the ManagedBean.

How is this done?

Thanks very much to all replies!!!

-- Mike
Sergey Smirnov
Ranch Hand

Joined: May 29, 2003
Posts: 167


Also, you can reach any session object using the Value Binding. For example:



--
Sergey : http://jsfTutorials.net
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
WOW!

Where did you learn that? <s>

That is not in my "Core JSF" book.

Clearly I need another reference book to compliment the Core book.

Thanks very very very much!!!

-- Mike
Sergey Smirnov
Ranch Hand

Joined: May 29, 2003
Posts: 167
I still recommend "Core JSF" :-)
See in the chapter 2:
* "Note" under the Table 2-2
* Table 2-4 (Predefined Objects)

--
Sergey : http://jsfTutorials.net
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
You're right, it *is* in Core JSF.... now that I know the answer, I see it. <s>

Perhaps this tecnhique would have been a good addition to the "how do I..." section in the later chapter: "How do I read a session variable in a JSF page / Managed Bean?"

Thanks very much again!!!

-- Mike
Alexander Jesse
Ranch Hand

Joined: Mar 17, 2004
Posts: 35
Actually:

FAQ 1
and
FAQ 2

Are FAQ-entries in that direction...

Therefor we have a new ressource to check... and (oh no) another forum to watch...
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
Thanks Alexnander!

-- M
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I read a session variable inside a Managed Bean?
 
Similar Threads
Bean value doubt
Accessing JSF sesson bean from a servlet
Access managed bean from a servlet
is there a mayor change on how to use faces-config.xml on JSF 2.0
managing Faces-config in jSF ...please explain.