Is there a way to access the target bean from within a Bean Validation field-level ConstraintValidator?

纵饮孤独 提交于 2019-12-23 03:38:10

问题


Apart from using class-level validations, is there a way to access the parent bean of a field-level validation annotation from within its validator class?

For example:

public class CustomValidator implements ConstraintValidator<CustomValidation, String> {

    @Override
    public void initialize(final CustomValidation constraintAnnotation) {
    }

    @Override
    public boolean isValid(final String fieldValue, final ConstraintValidatorContext context) {
        // is there a way to access the parent object here?
    }
}

回答1:


Upon further investigation, it turns out this is not possible with the version 1.1 of the spec.



来源:https://stackoverflow.com/questions/27007233/is-there-a-way-to-access-the-target-bean-from-within-a-bean-validation-field-lev

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