Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get and set the latest instance of ManagedBean from FacesContext?  RSS feed

 
Suhas Saheer
Greenhorn
Posts: 17
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

It would be of great help if you guys could suggest me a way to get and set the latest instance of a ManagedBean from FacesContext?
I have the "bean-Name" as the input.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You will have to cast it.
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the ugly way.

The pretty way is to simply inject the bean. Then a simple "set" method will provide the bean instance for you.

Going through the EL resolver is DEFINITELY the long way around. Managed Beans are simply ordinary J2EE application-, session- or request-scoped beans which are constructed and initialized by JSF. Once constructed, they're indistinguishable from their non-JSF siblings. So if you MUST "pull" a bean instead of letting injection "push" it, you can use the FacesContext to get the J2EE session or request object and obtain the attribute from there without fragile EL-dependent code.
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes. Almost forgot. There is no "latest instance" of a bean. There Can Be Only One.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!