Guice and JSF 2

Posted by digitaljoel on Stack Overflow See other posts from Stack Overflow or by digitaljoel
Published on 2009-12-28T22:05:41Z Indexed on 2010/03/13 9:55 UTC
Read the original article Hit count: 797

I'm trying to use Guice to inject properties of a JSF managed bean. This is all running on Google App Engine (which may or may not be important)

I've followed the instructions here:

http://code.google.com/docreader/#p=google-guice&s=google-guice&t=GoogleAppEngine

One problem is in the first step. I can't subclass the Servlet module and setup my servlet mappings there because Faces is handled by the javax.faces.webapp.FacesServlet which subclasses Servlet, not HttpServlet. So, I tried leaving my servlet configuration in the web.xml file and simply instantiating a new ServletModel() along with my business module when creating the injector in the context listener described in the second step.

Having done all that, along with the web.xml configuration, my managed bean isn't getting any properties injected. The method is as follows

@ManagedBean
@ViewScoped
public class ViewTables implements Serializable
{
    private DataService<Table> service;

    @Inject
    public void setService( DataService<Table> service )
    {
        this.service = service;
    }
    public List<Table> getTables()
    {
        return service.getAll();
    }
}

So, I'm wondering if there is a trick to get Guice injecting into a JSF managed bean? I obviously can't use the constructor injection because JSF needs a no-arg constructor to create the bean.

© Stack Overflow or respective owner

Related posts about jsf

Related posts about guice