Guice和JSF 2 [英] Guice and JSF 2

查看:129
本文介绍了Guice和JSF 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Guice来注入JSF托管bean的属性。这些都在Google App Engine上运行(这可能也可能不重要)



我已按照此处的说明操作:



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



一个问题是在第一步。我不能继承Servlet模块,并在那里设置我的servlet映射,因为Faces是由javax.faces.webapp.FacesServlet处理的,而Servlet的子类是Servlet,而不是HttpServlet。所以,我尝试在web.xml文件中留下我的servlet配置,并在第二步中描述的上下文监听器中创建注入器时简单地实例化一个新的ServletModel()以及我的业务模块。



完成了所有这些操作后,连同web.xml配置一起,我的托管bean没有注入任何属性。这个方法如下:

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b $ View $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ public $ ViewTables实现Serializable
{
private DataService< Table>服务;

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




$ b $ p
$ b $ p所以,我想知道是否有一个技巧让Guice注入JSF托管bean?我显然不能使用构造函数注入,因为JSF需要一个无参数构造函数来创建bean。 解决方案

检查以下内容JSF-Guice集成框架/建议:

http://code.google.com/p/jsf-sugar/



http://notdennisbyrne.blogspot.com/2007/09/integrating-guice-and-jsf.html



http://cagataycivici.wordpress .com / 2007/03/26 / integrate_guice_and_jsf /

http://snippets.dzone.com/posts/show/7171


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.

解决方案

Check the following JSF-Guice integration framework/advice:

http://code.google.com/p/jsf-sugar/

http://notdennisbyrne.blogspot.com/2007/09/integrating-guice-and-jsf.html

http://cagataycivici.wordpress.com/2007/03/26/integrating_guice_and_jsf/

http://snippets.dzone.com/posts/show/7171

这篇关于Guice和JSF 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆