• Post Reply Bookmark Topic Watch Topic
  • New Topic

Session Handling in JSF  RSS feed

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys! I came from Struts framework and pure Servlets and JSP. It's kind of new to me how HttpSession is not directly available through request.getSession() in the controller methods. So I'd like to ask how you guys handle session in JSF? Can it be done with the usual HttpSession or do you use managed beans for that or there's another way around? Thanks!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I used JSF I would create a single object called something like Visit that would have properties for all of my session data I planned to use. So it might have a User object, etc.

Then I would create a managed-bean for Visit and put it in SessionScope. I would then inject that bean into all my other managed beans and I would be able to read/write all my session data through the Visit object. Visit would be a property of a Base Bean that all my managed means would extend.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really, really want to, you can grub around and get your hands on the HttpSession object and do things the hard way.

Or, you can just declare your session objects as managed beans and have them handed, er, injected to you and not have to write all that funny specialized code - which, apart from being one more thing to remember, means that your components won't be as easy to move to the next New & Wonderful platform, whatever that may be.
[ May 01, 2007: Message edited by: Tim Holloway ]
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again! Thanks for your answers! I have another question in mind. In pure Servlets and JSP we could keep track of sessesion attributes for each controller. How do we do it in JSF with managed beans? Do Servlet Filters come in handy in this kind of situation too? But how? Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!