当前位置: 首页>>代码示例>>Java>>正文


Java ValidationUtils.invokeValidator方法代码示例

本文整理汇总了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());

}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:18,代码来源:SiteOptionTests.java

示例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++;
        }
    }
}
 
开发者ID:MaritimeConnectivityPlatform,项目名称:IdentityRegistry,代码行数:24,代码来源:VesselValidator.java

示例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);
  }
}
 
开发者ID:DISID,项目名称:springlets,代码行数:24,代码来源:CollectionValidator.java

示例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);

}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:9,代码来源:StoryRequestValidator.java

示例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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:MultiActionController.java

示例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++;
        }
    }
}
 
开发者ID:EMBL-EBI-SUBS-OLD,项目名称:subs,代码行数:23,代码来源:ListValidationUtils.java

示例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");
    }

}
 
开发者ID:EMBL-EBI-SUBS-OLD,项目名称:subs,代码行数:46,代码来源:SubmissionValidator.java

示例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);
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:6,代码来源:SpringFormWidget.java


注:本文中的org.springframework.validation.ValidationUtils.invokeValidator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。