Ilan Tal
Ilan Tal

Reputation: 499

Can I get information from both a session and view bean?

A user can open another tab on a browser and look at the same site. In this case he will have the same session but a different view. As an exercise I am constructing a jsf, primefaces site. The user first logs in and his log in information is stored in the session bean. If he then opens another tab, he could look at different pages of the site with each tab looking at a different page. This information I need to capture in view bean.

My question is, if I am in the view bean how can I get information from the session bean? This may be impossible, in which case, what is the best way to solve the problem?

Upvotes: 0

Views: 361

Answers (1)

Mikita Belahlazau
Mikita Belahlazau

Reputation: 15434

I suppose it is possible. You can access wider scoped bean from more narrow ones. E.g. you can access any kind of bean from request scoped. And application scoped bean can be used by any other bean. Try to inject your session scoped bean to view scoped. Like here:
http://www.mkyong.com/jsf2/injecting-managed-beans-in-jsf-2-0/

Also here is almost duplicate of your question: JSF2 Can't reach SessionScoped bean from ViewScoped as ManagedProperty

Upvotes: 2

Related Questions