Skip to content

Immutable object constructor arguments not considering WebDataBinder's FIELD_MARKER_PREFIX [SPR-15871] #20426

Closed

Description

@spring-projects-issues

Jean opened SPR-15871 and commented

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.


String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor));


Affects: 5.0 RC3

Issue Links:

Referenced from: commits 496223a, 9aa369f

Activity

  1. spring-projects-issues commented on Aug 18, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    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.

  2. spring-projects-issues commented on Aug 18, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Jean commented

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

  3. spring-projects-issues commented on Aug 20, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Indeed, I still need to port this and #19708 to WebFlux, possibly extracting some common delegate along the way. I'll wrap this up with #20432.

  4. added
    type: enhancement
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions