English 中文(简体)
Guice and JSF 2
原标题:

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.

最佳回答
问题回答

You can also create an HTTP servlet that then simple delegates the request on to a FacesServlet (like a wrapper). This should give you the same effect using Guice Servlet.

How about this approach, works well for us:

http://uudashr.blogspot.com/2008/12/guicing-jsf-with-guice.html

being the developer of jsf sugar I really would like to know the problem you had using it. We are already using it in production here so there shouldn t be any "show stoppers", maybe something is just not well documented? Just drop me a mail: murbanek(at)gmx_net (replace the _ with a .) .

check out http://code.google.com/p/guice2jsf/, and website starchu.blogspot.com, it has excellent library that provides Guice and JSF 2.0 integration

As information in this post are getting out of date but the question is still relevant, I d like to share my findings about this topic. I wrote a little tutorial including a runnable sample project on how to setup a fully guice powered web stack. You can find it here: https://github.com/skuzzle/guice-jsf





相关问题
How to make logging.debug work on Appengine?

I m having a tough time getting the logging on Appengine working. the statement import logging is flagged as an unrecognized import in my PyDev Appengine project. I suspected that this was just an ...

gqlQuery returns object, want list of keys

Is there a way to convert the GqlQuery object to an array of keys, or is there a way to force the query to return an array of keys? For example: items = db.GqlQuery("SELECT __key__ FROM Items") ...

Integrating Google AppEngine with a Thick Client

I want to make a multi-user client-server solution with Java Swing thick client as a front-end and Google AppEngine (Java one) as a back-end. The problem is that GAE provides only web-based forms for ...

sorl.thumbnail : thumbnail is not a valid tag library?

I am trying to install sorl.thumbnail but am getting the following error message: thumbnail is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module ...

热门标签