本文整理汇总了Java中org.springframework.validation.ValidationUtils.invokeValidator方法的典型用法代码示例。如果您正苦于以下问题:Java ValidationUtils.invokeValidator方法的具体用法?Java ValidationUtils.invokeValidator怎么用?Java ValidationUtils.invokeValidator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.validation.ValidationUtils
的用法示例。
在下文中一共展示了ValidationUtils.invokeValidator方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SiteOptionMapDtoValidationTests
import org.springframework.validation.ValidationUtils; //导入方法依赖的package包/类
@Test
public void SiteOptionMapDtoValidationTests() {
SiteOptionMapDTO siteOptionMapDTO = SiteOptionMapDTO.withGeneralSettings(
null,
siteOptions.getSiteDescription(),
siteOptions.getAddGoogleAnalytics(),
siteOptions.getGoogleAnalyticsTrackingId(),
siteOptions.getUserRegistration())
.build();
Errors errors = new BeanPropertyBindingResult(siteOptionMapDTO, "siteOptionMapDTO");
ValidationUtils.invokeValidator(new SiteOptionMapDtoValidator(), siteOptionMapDTO, errors);
assertTrue(errors.hasFieldErrors("siteName"));
assertEquals("EMPTY", errors.getFieldError("siteName").getCode());
}
示例2: validate
import org.springframework.validation.ValidationUtils; //导入方法依赖的package包/类
@Override
public void validate(Object target, Errors errors) {
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(target);
for (ConstraintViolation<Object> constraintViolation : constraintViolations) {
String propertyPath = constraintViolation.getPropertyPath().toString();
String message = constraintViolation.getMessage();
errors.rejectValue(propertyPath, "", message);
}
Vessel vessel = (Vessel) target;
if (vessel.getAttributes() != null) {
int i = 0;
for (VesselAttribute attribute : vessel.getAttributes()) {
try {
errors.pushNestedPath("attributes[" + i + "]");
ValidationUtils.invokeValidator(this.vesselAttributeValidator, attribute, errors);
} finally {
errors.popNestedPath();
}
i++;
}
}
}
示例3: validate
import org.springframework.validation.ValidationUtils; //导入方法依赖的package包/类
/**
* Validate each element inside the supplied {@link Collection}.
*
* The supplied errors instance is used to report the validation errors.
*
* @param target the collection that is to be validated
* @param errors contextual state about the validation process
*/
@Override
@SuppressWarnings("rawtypes")
public void validate(Object target, Errors errors) {
Collection collection = (Collection) target;
int index = 0;
for (Object object : collection) {
BeanPropertyBindingResult elementErrors = new BeanPropertyBindingResult(object,
errors.getObjectName());
elementErrors.setNestedPath("[".concat(Integer.toString(index++)).concat("]."));
ValidationUtils.invokeValidator(validator, object, elementErrors);
errors.addAllErrors(elementErrors);
}
}
示例4: validate
import org.springframework.validation.ValidationUtils; //导入方法依赖的package包/类
@Override
public void validate(Object o, Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors,"title","title.empty");
StoryRequest storyRequest = (StoryRequest) o;
geolocationValidator = new GeolocationValidator();
ValidationUtils.invokeValidator(this.geolocationValidator, storyRequest.getGeolocation(), errors);
}
示例5: bind
import org.springframework.validation.ValidationUtils; //导入方法依赖的package包/类
/**
* Bind request parameters onto the given command bean
* @param request request from which parameters will be bound
* @param command command object, that must be a JavaBean
* @throws Exception in case of invalid state or arguments
*/
protected void bind(HttpServletRequest request, Object command) throws Exception {
logger.debug("Binding request parameters onto MultiActionController command");
ServletRequestDataBinder binder = createBinder(request, command);
binder.bind(request);
if (this.validators != null) {
for (Validator validator : this.validators) {
if (validator.supports(command.getClass())) {
ValidationUtils.invokeValidator(validator, command, binder.getBindingResult());
}
}
}
binder.closeNoCatch();
}
示例6: invokeValidatorOnList
import org.springframework.validation.ValidationUtils; //导入方法依赖的package包/类
/**
* Use a validator on a list of objects, correctly handling changes to the nestedPath
*
* @param path
* @param validator
* @param list
* @param errors
*/
public static void invokeValidatorOnList(String path, Validator validator, List<?> list, Errors errors) {
int i = 0;
for (Object target : list) {
try {
errors.pushNestedPath(path + "[" + i + "]");
ValidationUtils.invokeValidator(validator, target, errors);
} finally {
errors.popNestedPath();
i++;
}
}
}
示例7: validate
import org.springframework.validation.ValidationUtils; //导入方法依赖的package包/类
@Override
public void validate(Object target, Errors errors) {
Submission submission = (Submission) target;
SubsApiErrors.rejectIfEmptyOrWhitespace(errors,"submitter");
SubsApiErrors.rejectIfEmptyOrWhitespace(errors,"team");
if (errors.hasErrors()) return;
try {
errors.pushNestedPath("team");
ValidationUtils.invokeValidator(this.teamValidator, submission.getTeam(), errors);
} finally {
errors.popNestedPath();
}
try {
errors.pushNestedPath("submitter");
ValidationUtils.invokeValidator(this.submitterValidator, submission.getSubmitter(), errors);
} finally {
errors.popNestedPath();
}
if (submission.getId() != null) {
Submission storedVersion = submissionRepository.findOne(submission.getId());
if (storedVersion != null) {
if (!operationControlService.isUpdateable(submission)) {
SubsApiErrors.resource_locked.addError(errors);
} else {
validateAgainstStoredVersion(submission, storedVersion, errors);
}
}
}
if (errors.hasErrors()) {
logger.error("validation has errors {}", errors.getAllErrors());
} else {
logger.error("no validation errors");
}
}
示例8: validateForm
import org.springframework.validation.ValidationUtils; //导入方法依赖的package包/类
protected void validateForm(T formBackingObject, BindingResult errors) {
if (this.validator != null) {
ValidationUtils.invokeValidator(this.validator, formBackingObject, errors);
}
}