user1482800
user1482800

Reputation: 83

Date in playframework 2.0-java is giving invalid value in form

I have a form where I define:

@Required
@Formats.DateTime(pattern="dd/MM/yyyy")
    public Date mDate;

Now my in template I have:

@helper.inputDate(
                myForm("mDate")
        )

But when I submit the form I get an error as invalid value.

Upvotes: 2

Views: 2947

Answers (2)

Berk
Berk

Reputation: 71

Check type of mDate field. It must be java.util.Date, not java.sql.Date.

Upvotes: 3

Bryant Kou
Bryant Kou

Reputation: 1739

This is really late, but hopefully it will be helpful to people who stumble upon this question.

If you go into chrome dev tools or firebug you'll see something like this when the error message is displayed:

<input type="date" id="start" name="start" value="2013-12-31">

That means the format sent back to the server is yyyy-MM-dd instead of dd/MM/yyyy.

Change the model field decorator to this:

@Required
@Formats.DateTime(pattern = "yyyy-MM-dd")
    public Date mDate;

Upvotes: 5

Related Questions