How do I access Request or Session from Seam?

JBoss daily recipe

Two ways :
1) Easy way: use ServletContexts.instance().getRequest() in your backing bean.

2) Define a factory in your component descriptor and inject the HttpServletRequest or HttpSession directly into your Seam component.

<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;

If on the other hand you don't need the HttpRequest but only the request parameters, simply use the  @RequestParameter("parameterName") annotation which inject into your component the value of a request parameter

Follow us on Twitter