如何在JSF 2中获取所有会话作用域的bean? [英] How to get all the session scoped beans in JSF 2?

查看:123
本文介绍了如何在JSF 2中获取所有会话作用域的bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,JSF将所有会话范围的bean保留在某种Map中(如果我错了,请纠正我.). 在我的应用程序中,我将会话范围(由Spring管理并注入到支持bean中)命名为"userDetailsBean"的bean.

As far as I know that JSF keeps all the session scoped bean in some kind of Map (correct me if I am wrong.). In my application I have session scoped (managed by Spring and injected into the backing bean) bean named "userDetailsBean".

是否可以借助JSF API在某种集合中获取为不同用户创建的Bean的所有实例?

Is it possible to get all the instances of the bean created for different user in some sort of collection by the help of JSF API?

推荐答案

@PostConstruct@PreDestroy期间将它们添加到某个应用程序范围的集合中/从中删除.

Add and remove them to/from some applicationwide collection/mapping yourself during @PostConstruct and @PreDestroy.

@PostConstruct
public void init() {
    allSessionScopedBeans.add(this);
}

@PreDestroy
public void destroy() {
    allSessionScopedBeans.remove(this);
}

这篇关于如何在JSF 2中获取所有会话作用域的bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆