CDI lifecycle of bean, @Inject and params

荒凉一梦 提交于 2019-12-04 22:02:32
jan groth

I understand your frustration, and I see that the problem is more your setup / understanding in general. But still, it's pretty hard to find any real questions to answer, maybe you can try to split your problems next time.

Here are some answers:

Why doesn't Detail.getComments() execute?

Hm, maybe because it's not in the bean? I guess that you are refrerring to detail.getContent instead?

which never seems to have, according to the above logs, Detail.getContent() invoked, despite that being part of the view:

Try rendered = true :-)

@PostConstruct
private void onLoad() {
    logger.log(level, "Detail.onLoad..{0}", getId());
}

You've put an awful lot of logic into the getter. Try debugging with the field, not with the getter...

The value 2000 is a default, which only happens when id==null, which it never should.

It looks like private String id = null; is a perfect explanation why id will be null.

Try to keep in mind that modern frameworks like JSF, CDI and Java EE do a lot of stuff behind the scenes, using reflection, proxies and interceptors. Don't rely on classical understanding of when (and how often) a constructor is called, for example.

Again, consider moving your initialisation logic away from the getter. @PostConstruct would be the place that the fathers of the Java EE-spec had chosen for it.

To be honest: Nothing looks extremely wrong, but your code is kind of messy, and extremely hard to understand and to follow.

Try removing all indirections like this one...

int b = Integer.parseInt(getId());

... and everything will look much better.

Oh, and is there a specific reason why you declare a fixed log-level for the whole class? Try something like this

private static final Logger LOG = Logger.getLogger(Some.class);
...
LOG.info("...");

Hope that gives you a start. Feel free to post further questions, preferably a bit shorter and with single, isolated aspects to answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!