简体   繁体   English

在jsf 2中处理用户会话

[英]Handling user session in jsf 2

I'm building a web application using jsf2. 我正在使用jsf2构建Web应用程序。 I use a @ManagedBean with a @SessionScope. 我使用@ManagedBean和@SessionScope。 In it I store the username etc in a User object. 我在其中将用户名等存储在User对象中。 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. 假设我要创建一个文章,为此,我有另一个@ManagedBean @RequestScope,它具有createArticle()方法,但是它需要设置文章作者。 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? 我是否应该通过cdi注入用户会话Bean以获取用户用户对象,是否可以将ManagedBeans注入其他托管Bean中? May be is there any other approach to would be better? 可能还有其他方法会更好吗?

The whole point of Dependency Injection is to inject managed beans into other managed beans. Dependency Injection的全部重点是将托管Bean注入其他托管Bean中。 So yes, your approach is the way to go. 是的,您的方法是正确的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM