本文整理匯總了Java中javax.validation.Validator.validateValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Validator.validateValue方法的具體用法?Java Validator.validateValue怎麽用?Java Validator.validateValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.validation.Validator
的用法示例。
在下文中一共展示了Validator.validateValue方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validate
import javax.validation.Validator; //導入方法依賴的package包/類
@Override
public void validate(Object value) throws ValidationException {
BeanValidation beanValidation = AppBeans.get(BeanValidation.NAME);
Validator validator = beanValidation.getValidator();
Class[] groups = this.validationGroups;
if (groups == null || groups.length == 0) {
groups = new Class[]{Default.class, UiComponentChecks.class};
}
@SuppressWarnings("unchecked")
Set<ConstraintViolation> violations = validator.validateValue(beanClass, beanProperty, value, groups);
if (!violations.isEmpty()) {
List<CompositeValidationException.ViolationCause> causes = new ArrayList<>();
for (ConstraintViolation violation : violations) {
causes.add(new BeanValidationViolationCause(violation));
}
String validationMessage = this.validationErrorMessage;
if (validationMessage == null) {
validationMessage = getDefaultErrorMessage();
}
throw new CompositeValidationException(validationMessage, causes);
}
}