ejbFacade为空 [英] ejbFacade is null
问题描述
我从jsf页面调用了managedBean OverzichtAlle.java overzichtAlleGroepen.xhtml
I call the managedBean OverzichtAlle.java from the jsf page overzichtAlleGroepen.xhtml
但是当我得到这个页面时,我得到了错误的事件,不能实例化managedBeans.OverzichtAlle由于Nullpointerexception ...
But when I get on this page i get the errormessage can't instantiate managedBeans.OverzichtAlle due to a Nullpointerexception...
当我调试时,我看到我的ejbFacade是空的..
When I debug, I see that my ejbFacade is null..
这是EJB
@EJB private ProjecttypeEFacade ejbFacade;
这是我的构造函数:
public OverzichtAlle()
{
projE = ejbFacade.findAll();
omvormenProjectTypes();
}
projE是一个列表(实体列表)
projE is a List (entity-list)
我做错了什么?
推荐答案
@EJB $在 bean的构造之后,c $ c>被注入。这是EJB注入管理器,即在构造之前不可能调用bean setter方法:
@EJB
s are injected after bean's construction. It's for the EJB injection manager namely not possible to call a bean setter method before constructing it:
overzichtAlle.setEjbFacade(ejbFacade);
OverzichtAlle overzichtAlle = new OverzichtAlle();
而是在幕后发生以下情况:
Instead, the following is happening behind the scenes:
OverzichtAlle overzichtAlle = new OverzichtAlle();
overzichtAlle.setEjbFacade(ejbFacade);
所以 ejbFacade
是 可以在bean的构造函数中使用。正常的做法是使用 @PostConstruct
方法。
So the ejbFacade
is not available inside bean's constructor. The normal approach is to use a @PostConstruct
method for this.
@PostConstruct
public void init() {
projE = ejbFacade.findAll();
omvormenProjectTypes();
}
A @PostConstruct
方法直接在 bean的构造和所有托管属性和依赖注入之后调用。您可以在其中执行与EJB相关的初始化作业。以下将在幕后发生:
A @PostConstruct
method is called directly after bean's construction and all managed property and dependency injections. You can do your EJB-dependent initializing job in there. The following will then happen behind the scenes:
OverzichtAlle overzichtAlle = new OverzichtAlle();
overzichtAlle.setEjbFacade(ejbFacade);
overzichtAlle.init();
请注意,方法名称无关紧要。但是,$ code> init()是非常自我记录的。
Note that the method name doesn't matter. But init()
is pretty self-documenting.
这篇关于ejbFacade为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!