jsf - @Inject-ed value null in @FacesComponent -
i have impression cdi not working classes have @javax.faces.component.facescomponent
. true?
here's example, doesn't work. myinjectableclass
used @ other points in code injection not problem, must @facescomponent
annotation think.
the class want inject:
@named @stateful public class myinjectableclass implements serializable { private static final long serialversionuid = 4556482219775071397l; }
the component uses class;
@facescomponent(value = "mycomponents.mytag") public class mycomponent extends uicomponentbase implements serializable { private static final long serialversionuid = -5656806814384095309l; @inject protected myinjectableclass injectedinstance; @override public void encodebegin(facescontext context) throws ioexception { /* injectedinstance null here */ } }
unfortunately, jsf 2.2 @facescomponent
, @facesvalidator
, @facesconverter
not valid injection targets (read what's new in jsf 2.2? arjan tijms more details). arjan points out:
it’s taken consideration jsf 2.3 though.
what can now? well, you've got 2 choices:
- handle cdi injection via lookup, or switch ejb , simpler ejb lookup;
- annotate tour class
@named
instead of@facescomponent
,@inject
component way did , register component in faces-config.xml.
and, way, you've got 2 issues you've got far: (1) meant @named @stateful
when former cdi world , latter ejb world , (2) sure intend keep state in faces component that's recreated on every request?
Comments
Post a Comment