Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16082

Checkbox/RadioButton incorrectly converts collections of enums with a custom converter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.3.11
    • Fix Version/s: 4.3.13, 5.0.1
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              laoseth Seth A Wilcox
              Last updater:
              Spring Issuemaster
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                39 weeks, 5 days ago