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

With WebDataBinder, the empty value of Boolean is not Null but FALSE [SPR-17513] #22045

Closed
spring-issuemaster opened this issue Nov 18, 2018 · 2 comments
Assignees

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Nov 18, 2018

yoshikawaa opened SPR-17513 and commented

With WebDataBinder, why the empty value of Boolean is not Null but FALSE ?

Form backing bean
public class SampleForm {
  private Boolean finished;
  // getter and setter...
}
Request Parameter
  • finished=true -> TRUE
  • finished=false -> FALSE
  • finished= -> Null
  • _finished= -> FALSE ???

 

"_" prefixed value is converted to empty value in WebDataBinder#getEmptyValue .

 

If we use 3 pattern value (TRUE, FALSE, Null(=default)), it may becomes a problem.

Because the result are different when explicitly sending finished= and when implicit _finished= is sent.

 

Thanks.


Affects: 4.3.20, 5.1.2

Reference URL: https://github.com/spring-projects/spring-framework/blob/v5.1.2.RELEASE/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java#L282-L285

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 18, 2018

Juergen Hoeller commented

A "_finished" field marker is explicitly meant to indicate that there was a checkbox that wasn't checked, effectively indicating false since an HTML form does not include a value parameter in such a case. No such field marker means that there actually was no such field, leading to null.

So if you'd like null for no value, then make sure that no field marker is sent along in the request.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 19, 2018

yoshikawaa commented

Thanks for your reply.

I understood this behavior is completely intentional by Spring MVC.

Depending on the requirements of the application, I will use Boolean property and marker parameter appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.