@Inject-ed value null in @FacesComponent

北战南征 提交于 2019-12-06 04:02:38
skuntsel

Unfortunately, even for JSF 2.2 @FacesComponent, @FacesValidator and @FacesConverter are not valid injection targets (read What's new in JSF 2.2? by Arjan Tijms for more details). As Arjan points out:

It’s likely that those will be taken into consideration for JSF 2.3 though.

What can you do for now? Well, you've got basically two choices:

  1. Handle CDI injection via lookup, or switch to EJB and do the simpler EJB lookup;
  2. Annotate tour class with @Named instead of @FacesComponent, @Inject the component the way you did and register your component in faces-config.xml. As the UI component instance is created via JSF Application#createComponent(), not via CDI you will also need a custom Application implementation as well (exactly like OmniFaces has for those converters/validators).

And, by the way, you've got two issues with what you've got this far: (1) what is meant by @Named @Stateful when the former is from a CDI world and the latter is from EJB world and (2) are you sure you intend to keep state in a faces component that's basically recreated on every request?

@FacesCompnent is managed by JSF and injection is not supported into them.

Passing the value in from the XHTML page via a composite component attribute worked for us.

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