JSF 注入的 bean 不适用于 Primefaces 树
我有一个托管 bean:
@ManagedBean
@ViewScoped
public class BeanA implements Serializable {
private TreeNode tree;
... }
我想将其注入,
@ManagedBean
@ViewScoped
public class BeanB extends Serializable {
@ManagedProperty(value="#{beanA}")
private BeanA injectedBean;
... getters and setters for injectedBean
}
但当我尝试在页面上通过 BeanB 引用 BeanA 的属性时,没有任何反应。具体来说,我正在尝试在 BeanB 支持的页面上重用 BeanA(primefaces 树的数据模型)的功能。也不会产生错误/堆栈跟踪。屏幕上不会输出树,但会在直接使用 BeanA 的页面上输出树。
I have a managed bean:
@ManagedBean
@ViewScoped
public class BeanA implements Serializable {
private TreeNode tree;
... }
and I want to inject it into
@ManagedBean
@ViewScoped
public class BeanB extends Serializable {
@ManagedProperty(value="#{beanA}")
private BeanA injectedBean;
... getters and setters for injectedBean
}
but nothing happens when I try to reference properties of BeanA through BeanB on a page. Specifically, I am attempting top reuse functionality of BeanA (the data model for a primefaces tree) on a page that is backed by BeanB. No errors/stack traces result either. No tree is output on the screen but the tree is output on a page that makes direct use of BeanA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将注释放在 Bean A 的 setter 上而不是成员上:
或者,使用 @Inject 而不是 @ManagedProperty
Put the annotation on a setter for Bean A rather than the member:
Alternatively, use @Inject instead of @ManagedProperty