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

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

Closed
spring-issuemaster opened this issue Aug 17, 2017 · 3 comments

Comments

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

commented Aug 17, 2017

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:

  • #19763 Data binding with immutable objects (Kotlin / Lombok / @ConstructorProperties)
  • #20101 BindingResult support for constructor argument mismatch on immutable data object
  • #20432 Revisit handling of missing fields (without default values) for immutable data classes

Referenced from: commits 496223a, 9aa369f

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 18, 2017

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.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 18, 2017

Jean commented

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 20, 2017

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.

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.