<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=soleg" rel="nofollow">Oleg Soloviov</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5528?redirect=false" rel="nofollow">SPR-5528</a></strong> and commented</p>
<ol dir="auto">
<li>You do some entries into the HTML form</li>
<li>submits the form</li>
<li>you do some changes to the form's entries on the server side</li>
<li>the changes are not displayed to the user, old entries remind in the form</li>
</ol>
<p dir="auto">Probably the bug is here:</p>
<p dir="auto">in the Constructor of the org.springframework.web.servlet.support.BindStatus<br>
it is<br>
=&gt;<br>
...<br>
this.errors = requestContext.getErrors(beanName, false);<br>
if (this.errors != null) {<br>
...<br>
} else {<br>
...<br>
}<br>
=&gt;<br>
the requestContext.getErrors returns errors Object that is not null but empty so (this.errors.hasErrors() is false)<br>
the else block is NEVER EXECUTED !!!</p>
<p dir="auto">The solution could be:<br>
=&gt;<br>
if (this.errors != null &amp;&amp; this.errors.hasErrors()) {<br>
...<br>
} else {<br>
...<br>
}<br>
=&gt;</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.5.6</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="398093597" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10212" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10212/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10212">#10212</a> MVC BindStatus does not interact with Web Flow's BindingModel (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=magnus" rel="nofollow">Magnus Heino</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-1047?redirect=false" rel="nofollow">SPR-1047</a></strong> and commented</p>
<p dir="auto">Bean definitions are required to provide a value for bean attributes defined as required using jdk1.5 annotation.</p>
<p dir="auto">This provides a check to validate that values are not "forgotten" when  creating new bean definitions. Values that are not properly set in the  bean definition and are not be used immediately after bean instantiation will not be found otherwise.</p>
<p dir="auto">package se.lantmateriet.jollen.bryggan.support;</p>
<p dir="auto">import java.lang.annotation.Documented;<br>
import java.lang.annotation.ElementType;<br>
import java.lang.annotation.Retention;<br>
import java.lang.annotation.RetentionPolicy;<br>
import java.lang.annotation.Target;</p>
<p dir="auto">/**</p>
<ul dir="auto">
<li>JDK 1.5+ method-level annotation that indicates that the value</li>
<li>is required to be non-null.</li>
<li></li>
<li><code class="notranslate">@author</code> Magnus Heino<br>
*/<br>
<code class="notranslate">@Target</code>(ElementType.FIELD)<br>
<code class="notranslate">@Retention</code>(RetentionPolicy.RUNTIME)<br>
<code class="notranslate">@Documented</code><br>
public <code class="notranslate">@interface</code> RequiredAttribute {<br>
}</li>
</ul>
<p dir="auto">/**<br>
*<br>
*/<br>
package se.lantmateriet.jollen.bryggan.support;</p>
<p dir="auto">import java.lang.reflect.Field;</p>
<p dir="auto">import org.springframework.beans.BeansException;<br>
import org.springframework.beans.MutablePropertyValues;<br>
import org.springframework.beans.factory.config.BeanDefinition;<br>
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;<br>
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;<br>
import org.springframework.beans.factory.support.BeanDefinitionValidationException;</p>
<p dir="auto">/**</p>
<ul dir="auto">
<li><code class="notranslate">@author</code> maghei</li>
<li></li>
</ul>
<p dir="auto">*/<br>
public class RequiredAttributeValidator implements BeanFactoryPostProcessor {</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/* (non-Javadoc)
 * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
 */
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

	for(String beanName: beanFactory.getBeanDefinitionNames()) {
		BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
		
		if(beanDefinition.isAbstract()) {
			continue;
		}
		
		MutablePropertyValues beanProperties = beanDefinition.getPropertyValues();
					
		for(Field field: beanFactory.getType(beanName).getDeclaredFields()) {
			RequiredAttribute requiredAttribute = field.getAnnotation(RequiredAttribute.class);
			if(requiredAttribute != null) {
				Object value = beanProperties.getPropertyValue(field.getName());
				if(value == null) {						
					throw new BeanDefinitionValidationException(&quot;Required attribute '&quot; + field.getName() + &quot;' of class '&quot; + beanDefinition.getClass().getName() + &quot;' defined in bean '&quot; + beanName + &quot;' in file '&quot; + beanDefinition.getResourceDescription() + &quot;' is  null.&quot;);
				} 
			}
		}		
		
	}
	
}"><pre class="notranslate"><code class="notranslate">/* (non-Javadoc)
 * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
 */
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

	for(String beanName: beanFactory.getBeanDefinitionNames()) {
		BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
		
		if(beanDefinition.isAbstract()) {
			continue;
		}
		
		MutablePropertyValues beanProperties = beanDefinition.getPropertyValues();
					
		for(Field field: beanFactory.getType(beanName).getDeclaredFields()) {
			RequiredAttribute requiredAttribute = field.getAnnotation(RequiredAttribute.class);
			if(requiredAttribute != null) {
				Object value = beanProperties.getPropertyValue(field.getName());
				if(value == null) {						
					throw new BeanDefinitionValidationException("Required attribute '" + field.getName() + "' of class '" + beanDefinition.getClass().getName() + "' defined in bean '" + beanName + "' in file '" + beanDefinition.getResourceDescription() + "' is  null.");
				} 
			}
		}		
		
	}
	
}
</code></pre></div>
<p dir="auto">}</p>
<hr>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/11395/RequiredPropertyValidator.java" rel="nofollow">RequiredPropertyValidator.java</a> (<em>9.67 kB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/11187/RequiredPropertyValidator.java" rel="nofollow">RequiredPropertyValidator.java</a> (<em>8.82 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="398061029" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/6119" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/6119/hovercard" href="https://github.com/spring-projects/spring-framework/issues/6119">#6119</a> Annotations for dependency checking (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>