[ 
https://issues.apache.org/struts/browse/WW-3140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46241#action_46241
 ] 

Musachy Barroso commented on WW-3140:
-------------------------------------

this was fixed in  trunk, it will be available in 2.1.7

> <s:select> converts the "listKey" to String before comparing to the Object in 
> "value"
> -------------------------------------------------------------------------------------
>
>                 Key: WW-3140
>                 URL: https://issues.apache.org/struts/browse/WW-3140
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - Tags
>    Affects Versions: 2.0.6
>         Environment: Jetty, all OS'es
>            Reporter: Jaron Schut
>
> Trying to get a populated and preselected select tag to work. Well, countries 
> is a list of country objects and country is a singular object of the 
> preselected country. Data comes from hibernate so are identified by Long 
> objects:
> <s:select list="countries" name="countryId" listKey="id" 
> listValue="displayLabel" value="country.id" />
> Now the preselecting does not work because the tag converts the listKey, 
> which is a Long object to a string before calling the equals method on the 
> Long object in the value. So a Long object and a String object are never 
> equal.
> Changing the tag to:
> <s:select list="countries" name="countryId" listKey="id" 
> listValue="displayLabel" value="%{country.id}" />
> Still does not correctly preselect the value because struts2 call 
> Long.toString() 2 separate times and then compares the result by reference. 
> Which obviously is String != String.
> Conclusion: <s:select> tag is not able to correctly compare 2 objects that 
> are the same nor correctly compare a single object because it creates 2 new 
> strings that apparently are not compared by value but only by reference?
> PS: changing the tag to:
> <s:select list="countries" name="countryCode" listKey="countryCode" 
> listValue="displayLabel" value="country.countryCode" />
> Did work correctly. Since the list of countries and the singular country all 
> come from hibernate. The tag ends up comparing 2 exactly the same 
> languageCode Strings (Same instance) correctly.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to