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

Immutable object constructor arguments not considering WebDataBinder's FIELD_MARKER_PREFIX

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 5.0 RC3
    • Fix Version/s: 5.0 RC4
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Unchecked checkbox value should be recognized via WebDataBinder#fieldMarkerPrefix.

      However when creating attribute, only constructor parameter names used, so field marker is not applied.

      When this html form submit:

      <form>
        <input type="checkbox" name="a" value="true">
        <input type="hidden" name="_a" value="on">
      </form>
      

      – kotlin code

      @Controller
      class TestController {
        class Form(val a: Boolean = true)
        
        @RequestMapping
        fun handle(@ModelAttribute form: Form) {
        }
      }
      
      

      when checkbox is unchecked, request should be:

      ?_a=on
      

      and the value of form.a should be false, but currently it remains true.


      https://github.com/spring-projects/spring-framework/blob/61cdc842e08f468c8aec9d10a900f3ba087f348e/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java#L238

        Issue Links

          Activity

          Hide
          juergen.hoeller Juergen Hoeller added a comment -

          Good point! We're considering field default values as well as field markers for constructor arguments as well now, using the settings (and the getEmptyValue implementation) from the provided WebDataBinder.

          Show
          juergen.hoeller Juergen Hoeller added a comment - Good point! We're considering field default values as well as field markers for constructor arguments as well now, using the settings (and the getEmptyValue implementation) from the provided WebDataBinder .
          Hide
          jean.ho Jean added a comment -

          I love it.
          Also hope webflux catch up these changes about ModelAttribute binding.

          Show
          jean.ho Jean added a comment - I love it. Also hope webflux catch up these changes about ModelAttribute binding.
          Hide
          juergen.hoeller Juergen Hoeller added a comment -

          Indeed, I still need to port this and SPR-15142 to WebFlux, possibly extracting some common delegate along the way. I'll wrap this up with SPR-15877.

          Show
          juergen.hoeller Juergen Hoeller added a comment - Indeed, I still need to port this and SPR-15142 to WebFlux, possibly extracting some common delegate along the way. I'll wrap this up with SPR-15877 .

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              jean.ho Jean
              Last updater:
              St├ęphane Nicoll
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

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