Tabnine Logo
org.springframework.validation.beanvalidation
Code IndexAdd Tabnine to your IDE (free)

How to use org.springframework.validation.beanvalidation

Best Java code snippets using org.springframework.validation.beanvalidation (Showing top 20 results out of 486)

origin: spring-projects/spring-framework

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
  if (this.afterInitialization) {
    doValidate(bean);
  }
  return bean;
}
origin: spring-projects/spring-framework

@Override
public void destroy() {
  close();
}
origin: spring-projects/spring-framework

/**
 * Specify a custom Spring MessageSource for resolving validation messages,
 * instead of relying on JSR-303's default "ValidationMessages.properties" bundle
 * in the classpath. This may refer to a Spring context's shared "messageSource" bean,
 * or to some special MessageSource setup for validation purposes only.
 * <p><b>NOTE:</b> This feature requires Hibernate Validator 4.3 or higher on the classpath.
 * You may nevertheless use a different validation provider but Hibernate Validator's
 * {@link ResourceBundleMessageInterpolator} class must be accessible during configuration.
 * <p>Specify either this property or {@link #setMessageInterpolator "messageInterpolator"},
 * not both. If you would like to build a custom MessageInterpolator, consider deriving from
 * Hibernate Validator's {@link ResourceBundleMessageInterpolator} and passing in a
 * Spring-based {@code ResourceBundleLocator} when constructing your interpolator.
 * <p>In order for Hibernate's default validation messages to be resolved still, your
 * {@link MessageSource} must be configured for optional resolution (usually the default).
 * In particular, the {@code MessageSource} instance specified here should not apply
 * {@link org.springframework.context.support.AbstractMessageSource#setUseCodeAsDefaultMessage
 * "useCodeAsDefaultMessage"} behavior. Please double-check your setup accordingly.
 * @see ResourceBundleMessageInterpolator
 */
public void setValidationMessageSource(MessageSource messageSource) {
  this.messageInterpolator = HibernateValidatorDelegate.buildMessageInterpolator(messageSource);
}
origin: spring-projects/spring-framework

@Test
public void testSpringValidationFieldType() {
  LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
  validator.afterPropertiesSet();
  ValidPerson person = new ValidPerson();
  person.setName("Phil");
  person.getAddress().setStreet("Phil's Street");
  BeanPropertyBindingResult errors = new BeanPropertyBindingResult(person, "person");
  validator.validate(person, errors);
  assertEquals(1, errors.getErrorCount());
  assertThat("Field/Value type mismatch", errors.getFieldError("address").getRejectedValue(),
      instanceOf(ValidAddress.class));
}
origin: spring-projects/spring-framework

@Test
public void testInnerBeanValidation() {
  LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
  validator.afterPropertiesSet();
  MainBean mainBean = new MainBean();
  Errors errors = new BeanPropertyBindingResult(mainBean, "mainBean");
  validator.validate(mainBean, errors);
  Object rejected = errors.getFieldValue("inner.value");
  assertNull(rejected);
}
origin: spring-projects/spring-framework

@Test  // SPR-16177
public void testWithList() {
  Parent parent = new Parent();
  parent.setName("Parent whit list");
  parent.getChildList().addAll(createChildren(parent));
  BeanPropertyBindingResult errors = new BeanPropertyBindingResult(parent, "parent");
  validatorAdapter.validate(parent, errors);
  assertTrue(errors.getErrorCount() > 0);
}
origin: spring-projects/spring-framework

@Test  // SPR-16177
public void testWithSet() {
  Parent parent = new Parent();
  parent.setName("Parent with set");
  parent.getChildSet().addAll(createChildren(parent));
  BeanPropertyBindingResult errors = new BeanPropertyBindingResult(parent, "parent");
  validatorAdapter.validate(parent, errors);
  assertTrue(errors.getErrorCount() > 0);
}
origin: spring-projects/spring-framework

@Test
public void testMethodValidationInterceptor() {
  MyValidBean bean = new MyValidBean();
  ProxyFactory proxyFactory = new ProxyFactory(bean);
  proxyFactory.addAdvice(new MethodValidationInterceptor());
  proxyFactory.addAdvisor(new AsyncAnnotationAdvisor());
  doTestProxyValidation((MyValidInterface) proxyFactory.getProxy());
}
origin: spring-projects/spring-framework

/**
 * Create AOP advice for method validation purposes, to be applied
 * with a pointcut for the specified 'validated' annotation.
 * @param validator the JSR-303 Validator to delegate to
 * @return the interceptor to use (typically, but not necessarily,
 * a {@link MethodValidationInterceptor} or subclass thereof)
 * @since 4.2
 */
protected Advice createMethodValidationAdvice(@Nullable Validator validator) {
  return (validator != null ? new MethodValidationInterceptor(validator) : new MethodValidationInterceptor());
}
origin: spring-projects/spring-framework

@Override
public void validate(Object target, Errors errors, Object... validationHints) {
  if (this.targetValidator != null) {
    processConstraintViolations(
        this.targetValidator.validate(target, asValidationGroups(validationHints)), errors);
  }
}
origin: spring-projects/spring-framework

  public static MessageInterpolator buildMessageInterpolator(MessageSource messageSource) {
    return new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(messageSource));
  }
}
origin: spring-projects/spring-framework

private List<Child> createChildren(Parent parent) {
  Child child1 = new Child();
  child1.setName("Child1");
  child1.setAge(null);
  child1.setParent(parent);
  Child child2 = new Child();
  child2.setName(null);
  child2.setAge(17);
  child2.setParent(parent);
  return Arrays.asList(child1, child2);
}
origin: spring-projects/spring-framework

@Override
public void validate(Object target, Errors errors) {
  if (this.targetValidator != null) {
    processConstraintViolations(this.targetValidator.validate(target), errors);
  }
}
origin: spring-projects/spring-framework

public void initialize(Same constraintAnnotation) {
  field = constraintAnnotation.field();
  comparingField = constraintAnnotation.comparingField();
  message = constraintAnnotation.message();
}
origin: spring-projects/spring-framework

public static class MainBean {
  @InnerValid
  private InnerBean inner = new InnerBean();
  public InnerBean getInner() {
    return inner;
  }
}
origin: spring-projects/spring-framework

@MyStereotype
public static class MyValidBean implements MyValidInterface<String> {
  @Override
  public Object myValidMethod(String arg1, int arg2) {
    return (arg2 == 0 ? null : "value");
  }
  @Override
  public void myValidAsyncMethod(String arg1, int arg2) {
  }
  @Override
  public String myGenericMethod(String value) {
    return value;
  }
}
origin: spring-projects/spring-framework

public static class ListContainer {
  @NotXList
  private List<String> list = new LinkedList<>();
  public void addString(String value) {
    list.add(value);
  }
  public List<String> getList() {
    return list;
  }
}
origin: spring-projects/spring-framework

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
  if (!this.afterInitialization) {
    doValidate(bean);
  }
  return bean;
}
origin: spring-projects/spring-framework

public static class MainBeanWithOptional {
  @InnerValid
  private InnerBean inner = new InnerBean();
  public Optional<InnerBean> getInner() {
    return Optional.ofNullable(inner);
  }
}
origin: spring-projects/spring-framework

@MyStereotype
public static class MyValidFactoryBean implements FactoryBean<String>, MyValidInterface<String> {
  @Override
  public String getObject() {
    return null;
  }
  @Override
  public Class<?> getObjectType() {
    return String.class;
  }
  @Override
  public Object myValidMethod(String arg1, int arg2) {
    return (arg2 == 0 ? null : "value");
  }
  @Override
  public void myValidAsyncMethod(String arg1, int arg2) {
  }
  @Override
  public String myGenericMethod(String value) {
    return value;
  }
}
org.springframework.validation.beanvalidation

Most used classes

  • LocalValidatorFactoryBean
    This is the central class for javax.validation (JSR-303) setup in a Spring application context: It b
  • MethodValidationPostProcessor
    A convenient BeanPostProcessor implementation that delegates to a JSR-303 provider for performing me
  • SpringValidatorAdapter
    Adapter that takes a JSR-303 javax.validator.Validator and exposes it as a Spring org.springframewor
  • BeanValidationPostProcessor
    Simple BeanPostProcessor that checks JSR-303 constraint annotations in Spring-managed beans, throwin
  • CustomValidatorBean
    Configurable bean class that exposes a specific JSR-303 Validator through its original interface as
  • MessageSourceResourceBundleLocator,
  • LocalValidatorFactoryBean$HibernateValidatorDelegate,
  • LocaleContextMessageInterpolator,
  • SpringConstraintValidatorFactory,
  • SpringValidatorAdapter$ResolvableAttribute,
  • MethodValidationTests$MyStereotype,
  • MethodValidationTests$MyValid,
  • MethodValidationTests$MyValidBean,
  • MethodValidationTests$MyValidInterface,
  • MethodValidationTests,
  • SpringValidatorAdapterTests$AnythingValid,
  • SpringValidatorAdapterTests$Child,
  • SpringValidatorAdapterTests$Parent,
  • SpringValidatorAdapterTests$Same
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now