Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring web flow, JSF and managedbean in servlet

 
Kumar Gaurav
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Saloon Keeper
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic