简体   繁体   中英

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.

Please advice how to get past this error.

thanks aj

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;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM