如何通过@ManagedProperty注释注入整个托管bean?
我试图通过 @ManagedProperty 注释将整个 JSF 托管 bean 注入另一个托管 bean(与 Possible 非常相似)将@ManagedBean 作为@ManagedProperty 注入@WebServlet?,但我注入的是bean,而不是servlet)。这就是我正在做的事情:
@ManagedBean
public class Foo {
@ManagedProperty(value = "#{bar}")
private Bar bar;
}
@ManagedBean
public class Bar {
}
不起作用(JSF 2.0/Mojarra 2.0.3):
SEVERE: JSF will be unable to create managed bean foo when it is
requested. The following problems where found:
- Property bar for managed bean foo does not exist. Check that
appropriate getter and/or setter methods exist.
是否可能,或者我需要通过FacesContext
以编程方式进行此注入?
I'm trying to inject entire JSF managed bean into another managed bean by means of @ManagedProperty
annotation (very similar to Possible to inject @ManagedBean as a @ManagedProperty into @WebServlet?, but I'm injecting into a bean, not a servlet). This is what I'm doing:
@ManagedBean
public class Foo {
@ManagedProperty(value = "#{bar}")
private Bar bar;
}
@ManagedBean
public class Bar {
}
Doesn't work (JSF 2.0/Mojarra 2.0.3):
SEVERE: JSF will be unable to create managed bean foo when it is
requested. The following problems where found:
- Property bar for managed bean foo does not exist. Check that
appropriate getter and/or setter methods exist.
Is it possible at all or I need to do this injection programmatically via FacesContext
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加setter和getter
当
FacesContext
将解析并注入依赖项时,它将使用setter注入,因此应该存在适当的setter/getters。否则它将找不到该属性You need to add setters and getters
When the
FacesContext
will resolve and inject dependencies it will use setters injection so appropriate setters/getters should be there.otherwise it won't find the property