跟踪应用程序中的用户
我需要跟踪登录到我的应用程序的用户,并且我正在尝试使用 JSF2 的 applicationMap 来实现此目的。因此,我创建了一个用户列表,并在登录 bean 中通过执行以下操作添加(删除)用户:
FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().put("usersList", usersList);
在 usersTracking.xhtml 页面的支持 bean 中,我尝试像这样检索列表:
AppllicationMap map = (ApplicationMap)FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
List users = (LinkedList)map.get("usersList");
但“users”始终为 null 。我做错了什么?
I need to track the users who are logged in to my application, and I'm trying to do this by using JSF2's applicationMap. So I create a list of users, and in my login bean I add (remove) users by doing this:
FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().put("usersList", usersList);
In the backing bean of the usersTracking.xhtml page I try to retrieve the list like this:
AppllicationMap map = (ApplicationMap)FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
List users = (LinkedList)map.get("usersList");
But "users" always comes as null. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将其设为应用程序范围的托管 bean 即可。
这样你就可以通过@ManagedProperty在每个任意托管bean中注入和访问它:
Just make it an application scoped managed bean.
This way you can inject and access it in every arbitrary managed bean by
@ManagedProperty
: