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.
| Online: | 34 Members of 4183 |
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).
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.
Just make sure you really need HttpServletRequest... request parameters are accessible with @RequestParameter