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

Spring formatters applied by to all numeric types [SPR-6490] #11156

Closed
spring-projects-issues opened this issue Dec 1, 2009 · 2 comments
Closed
Assignees
Labels
type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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:

@Size(min = 16, max = 16)
private Long creditCardNumber;

and this field is bound through Spring MVC:

<form:input path="creditCardNumber" />
<form:errors path="creditCardNumber"/>

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

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

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.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Hi guys,

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;

Regards,

Sam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants