<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=cbeams" rel="nofollow">Chris Beams</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-4975?redirect=false" rel="nofollow">SPR-4975</a></strong> and commented</p>
<p dir="auto">Today the <code class="notranslate">@MVC</code> programming model requires manual instantiation and invocation of Validator classes:</p>
<p dir="auto">public String onSubmit(<code class="notranslate">@ModelAttribute</code> Customer customer, BindingResult result) {<br>
new CustomerValidator().validate(customer, result);<br>
if(result.hasErrors()) {<br>
return "editAccount";<br>
}<br>
return "...";<br>
}</p>
<p dir="auto">It would be preferable to have validation be an integrated part of the <code class="notranslate">@MVC</code> lifecycle.</p>
<p dir="auto">For instance, Validator instances could be annotated as <code class="notranslate">@Component</code> and be subject to component scanning.  At any rate, whether declared via bean definitions or component scanned, registered Validator instances should be iterated through, and any returning true from Validator#supports() should be used to validate candidate objects.</p>
<p dir="auto">Additionally, I believe the interface-based approach is preferable here, vs a <code class="notranslate">@Validator</code> approach, because the strong contract of supports()-&gt;validate() is a useful and expressive one.  It would be sufficient to simply allow Validator instances to be component scanned.  We just need to add iterating through and invoking registered validators to the lifecycle.</p>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398048646" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/4803" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/4803/hovercard" href="https://github.com/spring-projects/spring-framework/issues/4803">#4803</a> Support for declarative validation (Hibernate Validator, anticipating JSR 303) (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=rwinch" rel="nofollow">Rob Winch</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7128?redirect=false" rel="nofollow">SPR-7128</a></strong> and commented</p>
<p dir="auto">Create a HandlerExceptionResolver that handles BindExceptions so that boilerplate code can be removed from controllers using <code class="notranslate">@Valid</code>. See the Spring forum reference for details.</p>
<p dir="auto">PS: I would be more than happy to contribute this</p>
<hr>
<p dir="auto"><strong>Reference URL:</strong> <a href="http://forum.springsource.org/showthread.php?t=87408" rel="nofollow">http://forum.springsource.org/showthread.php?t=87408</a></p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/16748/SPR-7128.patch" rel="nofollow">SPR-7128.patch</a> (<em>28.86 kB</em>)</li>
</ul>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398107366" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12196" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12196/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12196">#12196</a> Allow standard form "retry on error" logic to be handled by framework code instead of duplicated across <code class="notranslate">@Controller</code> code</li>
</ul>