wood burning stoves 2.0*
The moose likes JSF and the fly likes Spring web flow, JSF and managedbean in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Spring web flow, JSF and managedbean in servlet" Watch "Spring web flow, JSF and managedbean in servlet" New topic
Author

Spring web flow, JSF and managedbean in servlet

Kumar Gaurav
Ranch Hand

Joined: Apr 08, 2008
Posts: 108
Hi All,

I am using Spring web flow and JSF. My requirement is to access managedBean instance in a Servlet . For this i am using following lines of code :

FacesContextFactory contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
FacesContext facesContext = contextFactory.getFacesContext(request.getSession().getServletContext(), request, response, lifecycle);

Bean bean = (Bean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("bean");

but bean is coming null.

Any pointer how can i access bean instance.


Regards,
Gaurav
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

Patience is a virtue. We operate on a volunteer schedule here, so the cost of free advice is that it can take a little longer.

JSF's scope objects are plain old J2EE scope objects, for the most part, So if you define a JSF managed bean in Session scope, for example, a servlet can access it using the HttpServletRequest.getSession.getAttribute() method without any specialized JSF code.

There's also a specialized option you can put in your faces-config.xml file that allows Spring-managed beans to be seen by the JSF EL processor. That's useful for injecting Spring beans into JSF managed beans, and it's how I bind my Spring-managed persistence objects to the JSF presentation objects.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring web flow, JSF and managedbean in servlet