ejbFacade 为空

发布于 2024-11-29 09:28:44 字数 484 浏览 2 评论 0原文

我从 jsf 页面 overzichtAlleGroepen.xhtml 调用 ManagedBean OverzichtAlle.java

但是当我进入此页面时,我收到错误消息 Can't instantiate ManagedBeans.OverzichtAlle due to a NullpointerException...

当我调试时,我看到我的 ejbFacade 为 null ..

这是 EJB

@EJB private ProjecttypeEFacade ejbFacade;

,这是我的构造函数:

public OverzichtAlle() 
{
    projE = ejbFacade.findAll();
    omvormenProjectTypes();
}

projE 是一个列表(实体列表)

我做错了什么?

I call the managedBean OverzichtAlle.java from the jsf page overzichtAlleGroepen.xhtml

But when I get on this page i get the errormessage can't instantiate managedBeans.OverzichtAlle due to a Nullpointerexception...

When I debug, I see that my ejbFacade is null..

this is the EJB

@EJB private ProjecttypeEFacade ejbFacade;

and this is my constructor:

public OverzichtAlle() 
{
    projE = ejbFacade.findAll();
    omvormenProjectTypes();
}

projE is a List (entity-list)

What am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

树深时见影 2024-12-06 09:28:44

@EJB 在 bean 构造之后注入。对于 EJB 注入管理器来说,在构造 bean setter 方法之前不可能调用它:

overzichtAlle.setEjbFacade(ejbFacade);
OverzichtAlle overzichtAlle = new OverzichtAlle();

相反,在幕后发生以下情况:

OverzichtAlle overzichtAlle = new OverzichtAlle();
overzichtAlle.setEjbFacade(ejbFacade);

因此 ejbFacade 在内部可用bean 的构造函数。正常的方法是使用 @PostConstruct 方法。

@PostConstruct
public void init() {
    projE = ejbFacade.findAll();
    omvormenProjectTypes();
}

@PostConstruct 方法在 bean 构造以及所有托管属性和依赖项注入之后直接调用。您可以在那里完成依赖于 EJB 的初始化工作。然后将在幕后发生以下情况:

OverzichtAlle overzichtAlle = new OverzichtAlle();
overzichtAlle.setEjbFacade(ejbFacade);
overzichtAlle.init();

请注意,方法名称并不重要。但是 init() 是非常自文档化的。

@EJBs 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);

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 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();

Note that the method name doesn't matter. But init() is pretty self-documenting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文