Skip to content

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

Closed

Description

@spring-projects-issues

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

Activity

  1. spring-projects-issues commented on Jul 17, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

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

  2. spring-projects-issues commented on Aug 8, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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

  3. added
    type: enhancement
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions