Krishna
Krishna

Reputation: 7294

JSF - Difference in getting bean instance

HI,

There are many ways to get the bean instances from the JSF context. In the following two way:

Bean bean = (Bean) request.getAttribute("beanName");

and

FacesUtils.getManagedBean("beanName");

What is the difference in above two ways. In which case we have to use either ways. Please clarify me.

Upvotes: 1

Views: 513

Answers (1)

BalusC
BalusC

Reputation: 1108722

Use the first if you're not inside the JSF context (aka the FacesContext), e.g. inside a servlet. The second way is unclear since FacesUtils is not part of standard JSF implementation (it's likely a homegrown or 3rd party library). But if it grabs it by the FacesContext, then it works only when you're already inside the JSF context (i.e. inside a JSF managed bean).

Upvotes: 2

Related Questions