LocalValidatorFactoryBean implements both <code>javax.validation.Validator</code> and <code>org.springframework.validation.Validator</code>.
<classname>LocalValidatorFactoryBean</classname> implements both <code>javax.validation.Validator</code> and <code>org.springframework.validation.Validator</code>.
You may inject a reference to one of these two interfaces into beans that need to invoke validation logic.
</para>
<para>
Inject a reference to <code>javax.validation.Validator</code> if you prefer to work with the JSR-303 API directly:
Inject a reference to <code>org.springframework.validation.Validator</code> if your bean requires the Spring Validation API:
</para>
@ -1324,7 +1331,7 @@ public class MyService {
@@ -1324,7 +1331,7 @@ public class MyService {
At runtime, a <code>ConstraintValidatorFactory</code> instantiates the referenced implementation when the constraint annotation is encountered in your domain model.
</para>
<para>
By default, the <code>LocalValidatorFactoryBean</code> configures a <code>SpringConstraintValidatorFactory</code> that uses Spring to create ConstraintValidator instances.
By default, the <classname>LocalValidatorFactoryBean</classname> configures a <code>SpringConstraintValidatorFactory</code> that uses Spring to create ConstraintValidator instances.
This allows your custom ConstraintValidators to benefit from dependency injection like any other Spring bean.
</para>
<para>
@ -1355,9 +1362,9 @@ public class MyConstraintValidator implements ConstraintValidator {
@@ -1355,9 +1362,9 @@ public class MyConstraintValidator implements ConstraintValidator {
The default <code>LocalValidatorFactoryBean</code> configuration should prove sufficient for most cases.
The default <classname>LocalValidatorFactoryBean</classname> configuration should prove sufficient for most cases.
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.
See the JavaDocs of <classname>LocalValidatorFactoryBean</classname> more information on these options.
</para>
</section>
</section>
@ -1366,25 +1373,24 @@ public class MyConstraintValidator implements ConstraintValidator {
@@ -1366,25 +1373,24 @@ public class MyConstraintValidator implements ConstraintValidator {
<para>
Since Spring 3, a DataBinder instance can be configured with a Validator.
Once configured, the Validator may be invoked by calling <code>binder.validate()</code>.
Any validation Errors are automatically added to the binder's BindingResults.
Any validation Errors are automatically added to the binder's BindingResult.
</para>
<para>
When working with the DataBinder programatically, this can be used to invoke validation logic after binding to a target object:
</para>
<programlistinglanguage="java"><![CDATA[
Foo target = new Foo();
<programlistinglanguage="java">Foo target = new Foo();
DataBinder binder = new DataBinder(target);
binder.setValidator(new FooValidator());
// bind to the target object
<lineannotation>// bind to the target object</lineannotation>
binder.bind(propertyValues);
// validate the target object
<lineannotation>// validate the target object</lineannotation>
binder.validate();
// get BindingResults that include any validation errors
public void processFoo(<emphasisrole="bold">@Valid</emphasis> Foo foo) { <lineannotation>/* ... */</lineannotation> }
</programlisting>
<para>
Spring MVC will validate a @Valid object after binding so-long as an appropriate Validator has been configured.
</para>
@ -1457,7 +1460,7 @@ public class MyController {
@@ -1457,7 +1460,7 @@ public class MyController {
<para>
With JSR-303, the default <code>javax.validation.Validator</code> implementation is generic.
A single instance typically coordinates the validation of <emphasis>all</emphasis> application objects that declare validation constraints.
To configure such a general purpose Validator for use by Spring MVC, simply inject a <code>LocalValidatorFactoryBean</code> reference into the <code>WebBindingInitializer</code>.
To configure such a general purpose Validator for use by Spring MVC, simply inject a <classname>LocalValidatorFactoryBean</classname> reference into the <code>WebBindingInitializer</code>.
</para>
<para>
A full configuration example showing injection of a JSR-303 backed Validator into Spring MVC is shown below:
@ -1479,10 +1482,10 @@ public class MyController {
@@ -1479,10 +1482,10 @@ public class MyController {
<para>
With this configuration, anytime a @Valid @Controller input is encountered, it will be validated by the JSR-303 provider.
JSR-303, in turn, will enforce any constraints declared against the input.
Any ConstaintViolations will automatically be exposed as BindingResults renderable by standard Spring MVC form tags.
Any ConstaintViolations will automatically be exposed as errors in the BindingResult renderable by standard Spring MVC form tags.