<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=denis.zhdanov" rel="nofollow">Denis Zhdanov</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-6253?redirect=false" rel="nofollow">SPR-6253</a></strong> and commented</p>
<p dir="auto">Spring defines a contract for autowiring arrays and type collections (<a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ch03s04.html#beans-factory-autowire" rel="nofollow">3.4.5 Autowiring collaborators</a>, <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ch03s09.html#beans-autowired-annotation" rel="nofollow">3.9.2 @Autowired and @Inject</a>).</p>
<p dir="auto">However, there is a possible use-case that a user wants to define particular order for autowired collection/array. It looks obvious in the case of autowiring typed lists (the client may want to preserve particular order for the list elements) but the same idea may be spread easily to sets/maps/arrays.</p>
<p dir="auto">I suggest the following rules to be used during examining the order for two elements:</p>
<ul dir="auto">
<li>if both classes of compared object are marked by <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/core/annotation/Order.html" rel="nofollow">Ordered</a> the one with lower value is considered to be less than another;</li>
<li>if class of one element is marked by <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/core/annotation/Order.html" rel="nofollow">Ordered</a> and class of another is not marked by <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/core/annotation/Order.html" rel="nofollow">Ordered</a> the former is considered to be less than the later;</li>
<li>if both classes of compared elements are not marked by <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/core/annotation/Order.html" rel="nofollow">Ordered</a> but implement <a href="http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html" rel="nofollow">Comparable</a> with consisting type parameter they are compared via <a href="http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html#compareTo(T)" rel="nofollow">Comparable#compareTo(Object)</a>;</li>
</ul>
<p dir="auto">Please note that the rules above may be applied to all elements of autowired collection/array in order to define particular for them.</p>
<p dir="auto"><strong>Implementation</strong></p>
<p dir="auto">That feature may be optional and defaults to perform ordering. It seems that most natural to allow to define it via additional method of <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/annotation/Autowired.html" rel="nofollow">@Autowired</a> annotation.</p>
<p dir="auto">So, it can be implemented easily via minor <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.html" rel="nofollow">AutowiredAnnotationBeanPostProcessor</a> modification - the argument to be injected is just sorted if necessary.</p>
<p dir="auto">Attached archive contains either feature implementation (classes from <em>'org.springframework.beans.factory.annotation'</em> package) or usage example (classes from <em>'com.spring.example'</em> package and its subpackages).</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0 RC1</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/15824/ordered-autowired-collection.tar.gz" rel="nofollow">ordered-autowired-collection.tar.gz</a> (<em>9.63 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="398093786" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10245" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10245/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10245">#10245</a> Autowiring should support ordered collection driven by Order annotation or Ordered interface (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">8 votes, 6 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=joerg.heinicke@gmx.de" rel="nofollow">Jörg Heinicke</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-3461?redirect=false" rel="nofollow">SPR-3461</a></strong> and commented</p>
<p dir="auto">Didn't find a better summary ...</p>
<p dir="auto">My problem occurs when using spring:bind inside spring:nestedPath and form:form:</p>
<p dir="auto">&lt;form:form command="command"&gt;<br>
&lt;spring:nestedPath path="nestedPath"&gt;</p>
<p dir="auto">&lt;!-- ends in path nestedPath.test1 --&gt;</p>
<p dir="auto">&lt;spring:bind path="test1"/&gt;</p>
<p dir="auto">&lt;!-- ends in path command.nestedPath.test2 --&gt;</p>
<p dir="auto">&lt;form:input path="test2"/&gt;<br>
&lt;/spring:nestedPath&gt;<br>
&lt;/form:form&gt;</p>
<p dir="auto">As you see you get two different paths for spring:bind and form:input while I would expect to get the same for both. This is because form:input (actually AbstractDataBoundFormElementTag) has special handling for command while spring:bind is of course not aware of it. This could be made consistent by making form:form behave like spring:nestedPath with setting the command name as nestedPath.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.4</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="398068395" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/6988" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/6988/hovercard" href="https://github.com/spring-projects/spring-framework/issues/6988">#6988</a> provide form:transform tag</li>
</ul>
<p dir="auto">1 votes, 0 watchers</p>