• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get session scope backbean

 
Sam Sunamin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread may help you.

Link to page
 
Sam Sunamin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code should do it.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
RanjithRaj DhanaSekar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic