learn java
The moose likes JSF and the fly likes How to get session scope backbean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to get session scope backbean" Watch "How to get session scope backbean" New topic

How to get session scope backbean

Sam Sunamin
Ranch Hand

Joined: Mar 16, 2007
Posts: 113
I created on backbean which is define as a session scope backbean in face_config.xml.

Now how can retrieve this session bean's object? Which API I can use to get this session bean's Object?

Thank a lot in advance.

Yours Sam<br />SCJP5.0 97%<br />SCBCD5.0 72%
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

This thread may help you.

Link to page

My Blog SCJP 5 SCWCD 5
Sam Sunamin
Ranch Hand

Joined: Mar 16, 2007
Posts: 113
Hi Himanshu,

Thank you very much for your reply. However, the link didn't have an exact answer.

Do you have any other link to solve this out?
Duc Vo
Ranch Hand

Joined: Nov 20, 2008
Posts: 254
This code should do it.

“Everything should be as simple as it is, but not simpler.” Albert Einstein
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16540

The session bean is the object. JSF doesn't use magical constructs for managed beans. Managed Beans are just ordinary POJOs that are managed by the JSF framework.

So to get the session bean in non-JSF code (such as a servlet), just use the HttpServletRequest.getSession().getAttribute("beanname"); code construct and to get the session bean in JSF code, use JSF's faces-config.xml to inject it into the bean that references the session object.

Customer surveys are for companies who didn't pay proper attention to begin with.
RanjithRaj DhanaSekar

Joined: Aug 11, 2010
Posts: 3
Hi guys... I rearly sufferd with getting jsf frame work handled bean object refernce. But i got the solution. Hope it will usefull to all.
To get that reference object you have to manitain the <managed-bean> as applicaton scope

public class Report {

Report report;
int count;

public void updateCount()
FacesContext facesContext = FacesContext.getCurrentInstance();
Application app = facesContext.getApplication();
ValueBinding vlBinding = app.createValueBinding("#{report}");
Report uObj = (Report) vlBinding.getValue(facesContext);
uObj.setCount(uObj.getCount() + 1);

Can send feedback to ranjithraj.d@gmail.com
Have you tried LearnNowOnline? http://www.learnnowonline.com/
subject: How to get session scope backbean