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

@DateTimeFormat annotations are necessary both on field and constructor parameter in the immutable form class [SPR-16840] #21380

Closed
spring-projects-issues opened this issue May 18, 2018 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 18, 2018

Masatoshi Tada opened SPR-16840 and commented

public class SampleForm {

@NotBlank
private String message;

@NotNull
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate birthday;

public SampleForm(String message, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate birthday) {
    this.message = message;
    this.birthday = birthday;
}

public String getMessage() {
    return message;
}

public LocalDate getBirthday() {
    return birthday;
}

}

If field's annotation is missing, a value in textbox become "yy/MM/dd" when returning to input view.
If constructor parameter's annotation is missing, a validation error occurs in spite of inputting correct value.
So I have to add annotations to both of field and constructor parameter.
I think this is verbose.


Affects: 5.0.6

Reference URL: https://github.com/MasatoshiTada/spring-mvc-form-sample/blob/master/01-immutable/src/main/java/com/example/immutable/SampleForm.java

Issue Links:

Referenced from: commits 955665b

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This will be available in the upcoming 5.1.0.BUILD-SNAPSHOT. Please give it an early try...

@spring-projects-issues
Copy link
Collaborator Author

Masatoshi Tada commented

I upgraded my sample to Spring 5.1.RC1, and I found this issue was fixed! Thanks!

MasatoshiTada/spring-mvc-form-sample@03357f6#diff-e8fbdaff32189592f4b1858a9f878268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants