Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

FAQ Category:

You can use ServletContexts.instance().getRequest() in your backing bean.

Another approach is to define a factory in your component descriptor so that you can inject the HttpServletRequest or HttpSession directly into your Seam component. (Note, the default scope for a factory is event).

<factory name="httpRequest"
  value="#{facesContext.externalContext.request}"
  auto-create="true"/>
<factory name="httpSession"
  value="#{facesContext.externalContext.request.session}"
  auto-create="true"/>

@In HttpServletRequest httpRequest;
@In HttpSession httpSession;

You could also use the servletContexts component in the factory.

The only downside with the factory solution is that the casts to HttpServletRequest and HttpSession are masked (you are just assuming that is what they are).

2 comments:
 
19. Mar 2008, 17:38 CET | Link

For whatever reason that returns null for me in Seam 2.0.1.GA. I've had to do javax.faces.context.FacesContext.getCurrentInstance().getExternalContext().getRequest() instead.

ReplyQuote
 
22. Jul 2008, 08:52 CET | Link
Alex

Just make sure you really need HttpServletRequest... request parameters are accessible with @RequestParameter

Post Comment