vendredi 22 juillet 2016

Getting parent bean values for the Hibernate validator

I am using the Hibernate validator for my project. I would like to use a custom validator to reference another field from the parent bean inside the validator. How is this possible in Hibernate?

Bean

@NotNull(when="mvel:this.two == null")
private String one;

@NotNull(when="mvel:this.one == null")
private String two;

Validator

public class NotNullValidator implements ConstraintValidator<NotNull, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        //how do I get access to the parent bean here??
    }
}

I am using Hibernate 5.0.0, Jersey 2.6, JBoss 5, Java 6.

Aucun commentaire:

Enregistrer un commentaire