當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。