Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling a backing bean method with no user input

 
scott gaidos
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a session scope backing bean that I want to use for security authentication and authorization.

How can I invoke the methods on the bean from a JSP with no user interaction?
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All session scoped backing bean resides in the session of course. You can directly retrieve these beans as you normally do with session attributes, provided you know the id of the backing bean.
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case you decide you want to do it inside of a backing bean:

I beleive that's how you do it... there might be some mistakes but that's the general idea.
 
Sergey Smirnov
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just be careful with getting a reference to the managed bean from the session map directly. It might not be there yet. Managed Bean has a lazy initialization. It means the session scope managed bean is initialized and put in the session bean not at the moment the session is created, but when the managed bean is first time referenced.

This following code returns the reference to the managed bean and create it if it is not in the session map yet:



--
Sergey : http://jsfTutorials.net
[ March 19, 2006: Message edited by: Sergey Smirnov ]
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, by definition, a session-scoped object is ultimately the result of a user interaction. Where and how, of course, is the question.

Now if you want something to exist "before" anyone interacts, you'd use appliaction scope, instead.

Note that "before" may be an extremely short period of time, depending on who lazily the app initiailizes its contexts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic