You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The user enters a 15 digit number: 123456789012345 Spring MVC would convert and bind the field, validate it and return it to the form for correction. Only now the field is presented after a default formatting has been applied: 123,456,789,012,345. The user does now need to remove the default formatting to make the Long type valid again.
I think by default formatters for numeric types should be disabled to prevent such unexpected behaviour. Unless the user explicitly asks to format a value (using @NumberFormat(style=Style.CURRENCY)) it should not be applied.
Good point: Plain java.util number formatting is a fine default as well. java.text.NumberFormat style formatting will now only be applied through use of the @NumberFormat annotation.
I'm glad you already fixed this, as it was annoying me as well. ;)
In the interim, for anyone who is coding against Spring 3.0.0.RC3, you can annotate your numeric fields with @NumberFormat using the "0" pattern to achieve a similar (i.e., non-formatted) effect:
@NumberFormat(pattern = "0")
private Long creditCardNumber;
Stefan Schmidt opened SPR-6490 and commented
Assume there is the following use-case:
A form backing object contains the following field annotated with JSR 303:
and this field is bound through Spring MVC:
The user enters a 15 digit number: 123456789012345 Spring MVC would convert and bind the field, validate it and return it to the form for correction. Only now the field is presented after a default formatting has been applied: 123,456,789,012,345. The user does now need to remove the default formatting to make the Long type valid again.
I think by default formatters for numeric types should be disabled to prevent such unexpected behaviour. Unless the user explicitly asks to format a value (using
@NumberFormat
(style=Style.CURRENCY)) it should not be applied.Affects: 3.0 RC3
Referenced from: commits 73a7522
The text was updated successfully, but these errors were encountered: