JSF 2.3 Using a CDI managed Validator

Just like the previous blog entry "JSF 2.3 Using a CDI managed Converter" you can now do the same thing with Validators.

So how does that look in code?

    @FacesValidator(value="myValidator", managed=true)
    public class MyValidator implements Validator {

        MyModel model;

Note in this example the Validator would be a @RequestScoped bean as we did not state what CDI scope needs to manage it. You can use any other scope available to CDI. Beneath the covers we do not save the actual Validator instance into the view state, but we save the value "myValidator" so upon state restore we can ask CDI for the instance. And since we now have CDI managing the Validator you can also do @Inject into the Validator.

Posted January 16, 2015