Search code examples
javasessionjsf-2managed-beansession-scope

Handling user session in jsf 2


I'm building a web application using jsf2. I use a @ManagedBean with a @SessionScope. In it I store the username etc in a User object. Let's say I want to create an article, for that I have another @ManagedBean @RequestScope that has a createArticle() method, but it needs to set the article author. Should I inject the user session bean through cdi to get the user user object, is it ok to inject managedbeans into other managed beans? May be is there any other approach to would be better?


Solution

  • The whole point of Dependency Injection is to inject managed beans into other managed beans. So yes, your approach is the way to go.