Java Code Examples for org.springframework.web.bind.WebDataBinder#validate()

The following examples show how to use org.springframework.web.bind.WebDataBinder#validate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoRequestBodyProcessor.java    From summerframework with Apache License 2.0 6 votes vote down vote up
@Override
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
    if (AnnotatedElementUtils.hasAnnotation(parameter.getContainingClass(), ApiController.class)) {
        binder.validate();
    } else {
        Annotation[] annotations = parameter.getParameterAnnotations();
        for (Annotation ann : annotations) {
            Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
            if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
                Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
                Object[] validationHints = (hints instanceof Object[] ? (Object[])hints : new Object[] {hints});
                binder.validate(validationHints);
                break;
            }
        }
    }
}
 
Example 2
Source File: FormModelMethodArgumentResolver.java    From distributed-transaction-process with MIT License 6 votes vote down vote up
protected void validateComponent(WebDataBinder binder, MethodParameter parameter) throws BindException {

        boolean validateParameter = validateParameter(parameter);
        Annotation[] annotations = binder.getTarget().getClass().getAnnotations();
        for (Annotation annot : annotations) {
            if (annot.annotationType().getSimpleName().startsWith("Valid") && validateParameter) {
                Object hints = AnnotationUtils.getValue(annot);
                binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[]{hints});
            }
        }

        if (binder.getBindingResult().hasErrors()) {
            if (isBindExceptionRequired(binder, parameter)) {
                throw new BindException(binder.getBindingResult());
            }
        }
    }
 
Example 3
Source File: FormModelMethodArgumentResolver.java    From es with Apache License 2.0 6 votes vote down vote up
protected void validateComponent(WebDataBinder binder, MethodParameter parameter) throws BindException {

        boolean validateParameter = validateParameter(parameter);
        Annotation[] annotations = binder.getTarget().getClass().getAnnotations();
        for (Annotation annot : annotations) {
            if (annot.annotationType().getSimpleName().startsWith("Valid") && validateParameter) {
                Object hints = AnnotationUtils.getValue(annot);
                binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[]{hints});
            }
        }

        if (binder.getBindingResult().hasErrors()) {
            if (isBindExceptionRequired(binder, parameter)) {
                throw new BindException(binder.getBindingResult());
            }
        }
    }
 
Example 4
Source File: AbstractMessageConverterMethodArgumentResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Validate the binding target if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid},
 * Spring's {@link org.springframework.validation.annotation.Validated},
 * and custom annotations whose name starts with "Valid".
 * @param binder the DataBinder to be used
 * @param parameter the method parameter descriptor
 * @since 4.1.5
 * @see #isBindExceptionRequired
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
	Annotation[] annotations = parameter.getParameterAnnotations();
	for (Annotation ann : annotations) {
		Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
		if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
			Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
			Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
			binder.validate(validationHints);
			break;
		}
	}
}
 
Example 5
Source File: AbstractMessageConverterMethodArgumentResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Validate the binding target if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid},
 * Spring's {@link org.springframework.validation.annotation.Validated},
 * and custom annotations whose name starts with "Valid".
 * @param binder the DataBinder to be used
 * @param parameter the method parameter descriptor
 * @since 4.1.5
 * @see #isBindExceptionRequired
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
	Annotation[] annotations = parameter.getParameterAnnotations();
	for (Annotation ann : annotations) {
		Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
		if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
			Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
			Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
			binder.validate(validationHints);
			break;
		}
	}
}
 
Example 6
Source File: FormModelMethodArgumentResolver.java    From distributed-transaction-process with MIT License 5 votes vote down vote up
/**
 * Validate the model attribute if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid}.
 *
 * @param binder    the DataBinder to be used
 * @param parameter the method parameter
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
    Annotation[] annotations = parameter.getParameterAnnotations();
    for (Annotation annot : annotations) {
        if (annot.annotationType().getSimpleName().startsWith("Valid")) {
            Object hints = AnnotationUtils.getValue(annot);
            binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[]{hints});
        }
    }
}
 
Example 7
Source File: AbstractMessageConverterMethodArgumentResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validate the binding target if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid},
 * Spring's {@link org.springframework.validation.annotation.Validated},
 * and custom annotations whose name starts with "Valid".
 * @param binder the DataBinder to be used
 * @param parameter the method parameter descriptor
 * @since 4.1.5
 * @see #isBindExceptionRequired
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
	Annotation[] annotations = parameter.getParameterAnnotations();
	for (Annotation ann : annotations) {
		Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
		if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
			Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
			Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
			binder.validate(validationHints);
			break;
		}
	}
}
 
Example 8
Source File: ModelAttributeMethodProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validate the model attribute if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid},
 * Spring's {@link org.springframework.validation.annotation.Validated},
 * and custom annotations whose name starts with "Valid".
 * @param binder the DataBinder to be used
 * @param methodParam the method parameter
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter methodParam) {
	Annotation[] annotations = methodParam.getParameterAnnotations();
	for (Annotation ann : annotations) {
		Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
		if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
			Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
			Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
			binder.validate(validationHints);
			break;
		}
	}
}
 
Example 9
Source File: HandlerMethodInvoker.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void doBind(WebDataBinder binder, NativeWebRequest webRequest, boolean validate,
		Object[] validationHints, boolean failOnErrors) throws Exception {

	doBind(binder, webRequest);
	if (validate) {
		binder.validate(validationHints);
	}
	if (failOnErrors && binder.getBindingResult().hasErrors()) {
		throw new BindException(binder.getBindingResult());
	}
}
 
Example 10
Source File: AbstractMessageConverterMethodArgumentResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Validate the request part if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid},
 * Spring's {@link org.springframework.validation.annotation.Validated},
 * and custom annotations whose name starts with "Valid".
 * @param binder the DataBinder to be used
 * @param methodParam the method parameter
 * @see #isBindExceptionRequired
 * @since 4.1.5
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter methodParam) {
	Annotation[] annotations = methodParam.getParameterAnnotations();
	for (Annotation ann : annotations) {
		Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
		if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
			Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
			Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
			binder.validate(validationHints);
			break;
		}
	}
}
 
Example 11
Source File: ModelAttributeMethodProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Validate the model attribute if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid},
 * Spring's {@link org.springframework.validation.annotation.Validated},
 * and custom annotations whose name starts with "Valid".
 * @param binder the DataBinder to be used
 * @param methodParam the method parameter
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter methodParam) {
	Annotation[] annotations = methodParam.getParameterAnnotations();
	for (Annotation ann : annotations) {
		Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
		if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
			Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
			Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
			binder.validate(validationHints);
			break;
		}
	}
}
 
Example 12
Source File: HandlerMethodInvoker.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void doBind(WebDataBinder binder, NativeWebRequest webRequest, boolean validate,
		Object[] validationHints, boolean failOnErrors) throws Exception {

	doBind(binder, webRequest);
	if (validate) {
		binder.validate(validationHints);
	}
	if (failOnErrors && binder.getBindingResult().hasErrors()) {
		throw new BindException(binder.getBindingResult());
	}
}
 
Example 13
Source File: FormModelMethodArgumentResolver.java    From es with Apache License 2.0 5 votes vote down vote up
/**
 * Validate the model attribute if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid}.
 *
 * @param binder    the DataBinder to be used
 * @param parameter the method parameter
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
    Annotation[] annotations = parameter.getParameterAnnotations();
    for (Annotation annot : annotations) {
        if (annot.annotationType().getSimpleName().startsWith("Valid")) {
            Object hints = AnnotationUtils.getValue(annot);
            binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[]{hints});
        }
    }
}
 
Example 14
Source File: ModelAttributeMethodProcessor.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Validate the model attribute if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid},
 * Spring's {@link org.springframework.validation.annotation.Validated},
 * and custom annotations whose name starts with "Valid".
 * @param binder the DataBinder to be used
 * @param parameter the method parameter declaration
 * @see WebDataBinder#validate(Object...)
 * @see SmartValidator#validate(Object, Errors, Object...)
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
	for (Annotation ann : parameter.getParameterAnnotations()) {
		Object[] validationHints = determineValidationHints(ann);
		if (validationHints != null) {
			binder.validate(validationHints);
			break;
		}
	}
}
 
Example 15
Source File: ModelAttributeMethodProcessor.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Validate the model attribute if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid},
 * Spring's {@link org.springframework.validation.annotation.Validated},
 * and custom annotations whose name starts with "Valid".
 * @param binder the DataBinder to be used
 * @param parameter the method parameter declaration
 * @see WebDataBinder#validate(Object...)
 * @see SmartValidator#validate(Object, Errors, Object...)
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
	for (Annotation ann : parameter.getParameterAnnotations()) {
		Object[] validationHints = determineValidationHints(ann);
		if (validationHints != null) {
			binder.validate(validationHints);
			break;
		}
	}
}