Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox/RadioButton incorrectly converts collections of enums with a custom converter [SPR-16082] #20631

Closed
spring-issuemaster opened this issue Oct 17, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Oct 17, 2017

Seth A Wilcox opened SPR-16082 and commented

If you have an a collection of enums, for which you have implemented a custom org.springframework.core.convert.converter.Converter, the values are mapped from the form differently then they are mapped back to it. When spring reads the values from a submitted form, it runs the value supplied to the tag through the conversionService, so it expects the values to be in the checkbox/radiobox value field that the converter recognizes. However, when checking if the checkbox/radio button should be checked, it requires the value of the box to match the name() method of the enum, and does not run through the converter when checking for "equality' to mark the correct boxes checked. The issue seems to lie in org.springframework.web.servlet.tags.form.SelectedValueComparator.exhaustiveCompare(Object, Object, PropertyEditor, Map<PropertyEditor, Object>)

The logic first checks if the class we are binding to is an enum, and if it does, it checks against the toString of the enum. If that doesn't match, it then returns, skipping the PE compare later on, which would use the conversion service to properly convert the string to the appropriate type.

Basically, the else before the PE-Based comparison should be removed, to the conversion service always gets a chance to convert before the comparison


Affects: 4.3.11

Referenced from: commits 97c6385, ef6aef9

Backported to: 4.3.13

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 17, 2017

Juergen Hoeller commented

I've revised that algorithm accordingly. Could you please give it a try against this afternoon's 4.3.13.BUILD-SNAPSHOT?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 18, 2017

Seth A Wilcox commented

I was able to double check today, and the change in the nightly build fixes the issue. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.