<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=lisak" rel="nofollow">Josef Vychtrle</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8601?redirect=false" rel="nofollow">SPR-8601</a></strong> and commented</p>
<p dir="auto">There are two major means of data binding initialization, but there is a drawback in the oldschool xml one.</p>
<p dir="auto">In short, you can do this :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@InitBinder(&quot;order&quot;)
public void initBinder(WebDataBinder binder) {
    binder.setAllowedFields(allowedFields.split(&quot;,&quot;));
}"><pre class="notranslate"><code class="notranslate">@InitBinder("order")
public void initBinder(WebDataBinder binder) {
    binder.setAllowedFields(allowedFields.split(","));
}
</code></pre></div>
<p dir="auto">but it can't be done with ConfigurableWebBindingInitializer. First off, the binder instance is created in AnnotationMethodHandlerAdapter and initializer is passed the binder instance somewhere in HandlerMethodInvoker so it can't be set up... :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;bean id=&quot;webBindingInitializer&quot; class=&quot;org.springframework.web.bind.support.ConfigurableWebBindingInitializer&quot;&gt;
    &lt;property name=&quot;messageCodesResolver&quot; ref=&quot;codesResolver&quot; /&gt;
    &lt;!-- missing allowed / disallowed / required  properties --&gt;
&lt;/bean&gt;"><pre class="notranslate"><code class="notranslate">&lt;bean id="webBindingInitializer" class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer"&gt;
    &lt;property name="messageCodesResolver" ref="codesResolver" /&gt;
    &lt;!-- missing allowed / disallowed / required  properties --&gt;
&lt;/bean&gt;
</code></pre></div>
<p dir="auto">FIX :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public void initBinder(WebDataBinder binder, WebRequest request) {
     if(this.allowedFields != null) {
                   binder.setAllowedFields(allowedFields);
           }
           if(this.disallowedFields != null) {
                   binder.setDisallowedFields(disallowedFields);
           }
                         if(this.allowedFields != null) {
                   binder.setRequiredFields(requiredFields);
           }
           if (this.directFieldAccess) {
          binder.initDirectFieldAccess();
     }
     if (this.messageCodesResolver != null) {
          binder.setMessageCodesResolver(this.messageCodesResolver);
     }
     if (this.bindingErrorProcessor != null) {
          binder.setBindingErrorProcessor(this.bindingErrorProcessor);
     }
     if (this.validator != null &amp;&amp; binder.getTarget() != null &amp;&amp;
               this.validator.supports(binder.getTarget().getClass())) {
          binder.setValidator(this.validator);
     }
     if (this.conversionService != null) {
          binder.setConversionService(this.conversionService);
     }
     if (this.propertyEditorRegistrars != null) {
          for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) {
               propertyEditorRegistrar.registerCustomEditors(binder);
          }
     }
}"><pre class="notranslate"><code class="notranslate">public void initBinder(WebDataBinder binder, WebRequest request) {
     if(this.allowedFields != null) {
                   binder.setAllowedFields(allowedFields);
           }
           if(this.disallowedFields != null) {
                   binder.setDisallowedFields(disallowedFields);
           }
                         if(this.allowedFields != null) {
                   binder.setRequiredFields(requiredFields);
           }
           if (this.directFieldAccess) {
          binder.initDirectFieldAccess();
     }
     if (this.messageCodesResolver != null) {
          binder.setMessageCodesResolver(this.messageCodesResolver);
     }
     if (this.bindingErrorProcessor != null) {
          binder.setBindingErrorProcessor(this.bindingErrorProcessor);
     }
     if (this.validator != null &amp;&amp; binder.getTarget() != null &amp;&amp;
               this.validator.supports(binder.getTarget().getClass())) {
          binder.setValidator(this.validator);
     }
     if (this.conversionService != null) {
          binder.setConversionService(this.conversionService);
     }
     if (this.propertyEditorRegistrars != null) {
          for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) {
               propertyEditorRegistrar.registerCustomEditors(binder);
          }
     }
}
</code></pre></div>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 M2</p>
<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="398113977" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13244" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13244/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13244">#13244</a> ConfigurableWebBindingInitializer should have allowed / disallowed / required fields for DataBinder initialization (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=pmularien" rel="nofollow">Peter Mularien</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-3695?redirect=false" rel="nofollow">SPR-3695</a></strong> and commented</p>
<p dir="auto">A very common issue with new adopters of Spring MVC is confusion over how to get JSTL working in their application server. Although the Spring docs can't possibly cover every application server, since I try to help out newbies on the forums, I've noticed a few common problems/pitfalls that might be worthwhile to document in section 14.2 of the documentation.</p>
<p dir="auto">The basis for some of this is that for a lot of people, when using Spring MVC, they are also attempting to use JSTL for the first time. So although some of the blame for these common issues falls on Sun, I think it would be worthwhile to cover some of them in the Spring docs, because people ultimately come to the Spring Web forums to get them solved (thinking that they are Spring problems).</p>
<p dir="auto">Here's a few suggestions, feel free to document some or all of them.</p>
<p dir="auto">The most common problem is people trying to use JSTL without declaring their web application as a servlet 2.4 (or higher) web app. In compliant application servers (most commonly reported is Tomcat), this will disable JSTL 2.0 evaluation. The documentation should provide an example web.xml snippet illustrating where the webapp version is set, and indicate the minimum required version to get JSTL 2.0 evaluation (a list of app servers supporting this would be nice, too ;) ).</p>
<p dir="auto">There are many, many threads in the Spring Web forum regarding this confusion. Do a search with the terms "+jstl +version". Examples:<br>
<a href="http://forum.springframework.org/showthread.php?t=35085&amp;highlight=jstl+version" rel="nofollow">http://forum.springframework.org/showthread.php?t=35085&amp;highlight=jstl+version</a><br>
<a href="http://forum.springframework.org/showthread.php?t=38850&amp;highlight=jstl+version" rel="nofollow">http://forum.springframework.org/showthread.php?t=38850&amp;highlight=jstl+version</a><br>
<a href="http://forum.springframework.org/showthread.php?t=27858&amp;highlight=jstl+version" rel="nofollow">http://forum.springframework.org/showthread.php?t=27858&amp;highlight=jstl+version</a><br>
... etc.</p>
<p dir="auto">Another common problem is people being confused over which JSTL taglib declaration to use, and how to reference JSTL within the page.</p>
<p dir="auto">More documentation on how to set up JSTL with MessageSourceAccessors, along with an example.</p>
<p dir="auto">I can't think of anything else at the moment, but I'd suggest reviewing some of the recent forum postings for ideas on additional topics. I always found it kind of odd that the documentation for how to use Spring with FreeMarker is more dense than the docs for Spring + JSP/JSTL :)</p>
<p dir="auto">Part of the problem (I think) is that the only MVC tutorial that's on the web site (step-by-step) is extremely outdated. It would be great if we could put together an example that is as simple, while being updated for Spring 2.x (but that's the topic of another JIRA).</p>
<p dir="auto">Let me know if I can help at all with this effort.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.6</p>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/89d997a5bcc396d1bf666ccc8d7b11e092e32b75/hovercard" href="https://github.com/spring-projects/spring-framework/commit/89d997a5bcc396d1bf666ccc8d7b11e092e32b75"><tt>89d997a</tt></a></p>
<p dir="auto">4 votes, 5 watchers</p>