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

      Unable to find source-code formatter for language: kotlin. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      @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

        Attachments

          Issue Links

            Activity

              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:
                  43 weeks, 6 days ago