eclipse-ee4j / mojarra

Mojarra, a Jakarta Faces implementation
Other
163 stars 111 forks source link

Injection in @FacesValidator #5119

Closed chris21k closed 1 year ago

chris21k commented 2 years ago

With Mojarra 4.0.0 and Weld 5.0.0.SP2 injection in a @FacesValidator now works as desired with an annotation @FacesValidator{managed = true), instead of the previously necessary @FacesValidator(value = xxxValidator, managed = true). I believe this was the fix for issue #5075 . So far, so good/great.

However, as long time ago stated in #4245, more precisely in https://github.com/eclipse-ee4j/mojarra/issues/4245#issuecomment-382262305 , it is still necessary to use bean-discovery-mode="all" in beans.xml instead of bean-discovery-mode="annotated". The latter is even default now, for a good reason. However, the bug that injected values in a managed FacesValidator then are null is now even more misleading. Probably related #5110.

I hope fixing this bug closes the injection in validator odyssey.

Many thanks @BalusC and at all other involved people for the fix of #5075 and for looking into this remaining issue. Thank you all for Jakarta Faces and Mojarra in the great new version 4!

Chris

pizzi80 commented 2 years ago

However, as long time ago stated in #4245, more precisely in #4245 (comment) , it is still necessary to use bean-discovery-mode="all" in beans.xml instead of bean-discovery-mode="annotated". The latter is even default now, for a good reason. However, the bug that injected values in a managed FacesValidator then are null is now even more misleading. Probably related #5110.

now I understand why for me @Inject never worked!!

BalusC commented 2 years ago

Work around: put a CDI scope annotation on the validator, e.g. @Dependent or @ApplicationScoped, depending on the desired scope of the state of the validator instance.

mnriem commented 1 year ago

@chris21k This is by design.

Note that CDI determines what happens when you use the 'bean-discovery-mode'.

See https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#default_bean_discovery

Closing this as works as designed

pizzi80 commented 1 year ago

So basically for Faces 4+ the "managed" attribute of @FacesValidator it's useless and confusing and probably should be removed

The best way for Faces 5? it's to obtain a Faces Validator only with CDI.

In this way we will obtain the following results: 1) remove a useless attribute 2) optimize the validators lifecycle 3) reduce the code inside Faces 4) optimize the memory usage