Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mike London
Ranch Hand
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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



--
Sergey : http://jsfTutorials.net
 
Mike London
Ranch Hand
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Alexnander!

-- M
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic