<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=jslate" rel="nofollow">Jonathan Slate</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-3464?redirect=false" rel="nofollow">SPR-3464</a></strong> and commented</p>
<p dir="auto">When loading a form using SimpleFormController, if the Object formBackingObject provides contains an Object that also exists in a list of Objects within the Map provided by referenceData, those two objects must be exactly equivalent (equals method) in order to have the correct item selected in a drop-down list (or similar). I'd like to instead be able to have the Object's PropertyEditor's getAsText method used to get a String representation of the Objects, and have the Strings compared. This could either be the default behavior or a settable option.</p>
<p dir="auto">Here's an example: you have form where a user can edit their address. The form backing Object is a Person which contains several address fields including a Country. With referenceData you also provide a Map that includes a list of all countries in the world. The form will include a drop-down menu with a list of all countries, and the Person's current Country should be pre-selected from that list. With the current behavior, the Person's Country and the Country in the list of countries must be equivalent (equals returns true) for the pre-selection to occur. I'd like to be able to use the CountryEditor property editor to compare the ID numbers instead. This way, if they have the same ID number they are considered equivalent within the form, without having to override the equals method.</p>
<p dir="auto">Also, when you submit the form, setAsText is used to take the ID that is sent to the server and turn it into an actual Country object. So using getAsText when the form loads as described above seems more consistent with the behavior that occurs when the form submits.</p>
<p dir="auto">There is a discussion in the Spring forums on this topic here:<br>
<a href="http://forum.springframework.org/showthread.php?t=38332" rel="nofollow">http://forum.springframework.org/showthread.php?t=38332</a></p>
<p dir="auto">Jörg Heinicke states in that thread more eloquently than I can:<br>
You have some really valid points. At the end you externalize the object comparisons (normally done by equals()) to the property editors (done by string representations) and so make it reusable and changeable. The comparison criteria of an object type might change in different use cases (changeable). Or the same comparison criteria might apply to different object types (reusable), e.g. all persistent objects can be compared by their ID - and you neither need to duplicate this equals() code nor introduce an abstract base class.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.1</p>
<p dir="auto">3 votes, 4 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=aldana" rel="nofollow">Manuel Aldana</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-4239?redirect=false" rel="nofollow">SPR-4239</a></strong> and commented</p>
<p dir="auto">java.lang.Properties are bound to xml configuration:<br>
&lt;props&gt;<br>
&lt;prop key="any.key"&gt;anyValue&lt;/prop&gt;<br>
&lt;/props&gt;</p>
<p dir="auto">a shorter, less verbose version would be better readable, for instance like following:<br>
&lt;props&gt;<br>
&lt;prop key="any.key" value="anyValue"/&gt;<br>
&lt;/props&gt;</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.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="398083757" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/8916" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/8916/hovercard" href="https://github.com/spring-projects/spring-framework/issues/8916">#8916</a> Support value on prop tag (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>