diff --git a/spring-framework-reference/src/validation.xml b/spring-framework-reference/src/validation.xml index 9ffceec8894..701d96794c9 100644 --- a/spring-framework-reference/src/validation.xml +++ b/spring-framework-reference/src/validation.xml @@ -1278,7 +1278,7 @@ public class Person { Injecting a Validator LocalValidatorFactoryBean implements both javax.validation.Validator and org.springframework.validation.Validator. - Inject a reference to one of these two interfaces into beans that need to invoke validation logic. + You may inject a reference to one of these two interfaces into beans that need to invoke validation logic. Inject a reference to javax.validation.Validator if you prefer to work with the JSR-303 API directly: @@ -1295,7 +1295,7 @@ public class MyService { }]]> - Inject a reference to org.springframework.validation.Validator if your bean depends on the existing Spring Validation API: + Inject a reference to org.springframework.validation.Validator if your bean requires the Spring Validation API: javax.validation.ConstraintValidator interface that implements the constraint's behavior. - To associate a declaration with an implementation, each @Constraint annotation references its corresponding ValidationConstraint implementation class. - At runtime, the ConstraintValidatorFactory then creates instances of this class when the constraint annotation is encountered in your domain model. + To associate a declaration with an implementation, each @Constraint annotation references a corresponding ValidationConstraint implementation class. + At runtime, a ConstraintValidatorFactory instantiates the referenced implementation when the constraint annotation is encountered in your domain model. - The LocalValidatorFactoryBean automatically configures a SpringConstraintValidatorFactory that uses Spring to create ConstraintValidator instances. + By default, the LocalValidatorFactoryBean configures a SpringConstraintValidatorFactory that uses Spring to create ConstraintValidator instances. This allows your custom ConstraintValidators to benefit from dependency injection like any other Spring bean. - Below is an example of a custom constraint declaration and implementation that uses Spring dependency injection: + Shown below is an example of a custom Constraint declaration, followed by an associated ConstraintValidator implementation that uses Spring for dependency injection: - As you can see, the ConstraintValidator implementation above can have its dependencies @Autowired by Spring like any other bean. + As you can see, a ConstraintValidator implementation may have its dependencies @Autowired like any other Spring bean.
Additional Configuration Options The default LocalValidatorFactoryBean configuration should prove sufficient for most cases. - There are a number of other explicit configuration options for various JSR-303 constructs, from message interpolation to traversal resolution. + There are a number of other configuration options for various JSR-303 constructs, from message interpolation to traversal resolution. See the JavaDocs of LocalValidatorFactoryBean more information on these options.
@@ -1360,20 +1360,21 @@ public class MyConstraintValidator implements ConstraintValidator { Configuring a DataBinder Since Spring 3, a DataBinder instance can now be configured with a Validator. - Once configured, the Validator may be subsequently invoked by calling binder.validate(). + Once configured, the Validator may be invoked by calling binder.validate(). Any validation Errors are automatically added to the binder's BindingResults. - When working with the DataBinder programatically, this feature can be used to invoke validation logic after binding to a target object: + When working with the DataBinder programatically, this can be used to invoke validation logic after binding to a target object: Configuring a JSR-303 Validator for use by Spring MVC - With JSR-303, the default javax.validation.Validator implementation is quite generic. + With JSR-303, the default javax.validation.Validator implementation is generic. A single instance typically coordinates the validation of all application objects that declare validation constraints. - To configure such a Validator for use by Spring MVC, simply inject a LocalValidatorFactoryBean reference into the WebBindingInitializer. - LocalValidatorFactoryBean already implements org.springframework.validation.Validation, delegating to the JSR-303 provider underneath. + To configure such a general purpose Validator for use by Spring MVC, simply inject a LocalValidatorFactoryBean reference into the WebBindingInitializer. + LocalValidatorFactoryBean already implements org.springframework.validation.Validator, and delegates to the JSR-303 provider underneath. A full configuration example showing injection of a JSR-303 backed Validator into Spring MVC is shown below: @@ -1472,7 +1473,9 @@ public class MyController { ]]> - With this configuration, anytime a @Valid @Controller method argument is encountered, it will be validated using the JSR-303 provider. + With this configuration, anytime a @Valid @Controller method argument is encountered, it will be validated by the JSR-303 provider. + JSR-303, in turn, will enforce any constraints declared against the argument. + Any ConstaintViolations will automatically be exposed as BindingResults renderable by standard Spring MVC form tags.