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-projects-issues opened this issue Aug 17, 2017 · 3 comments
Assignees
Labels
in: web type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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:

Referenced from: commits 496223a, 9aa369f

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues 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-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 18, 2017

Jean commented

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues 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
Labels
in: web type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants