user1220373
user1220373

Reputation: 385

How to get all the session scoped beans in JSF 2?

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".

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?

Upvotes: 7

Views: 1417

Answers (1)

BalusC
BalusC

Reputation: 1108642

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);
}

Upvotes: 10

Related Questions