html input with date type binding java attribute date

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

html input with date type binding java attribute date


I use <input type="date" in my html page,  this input box is mapped to the attribut date of my java bean Bean.

When i click on the submit button,  i got a white label page error.  If i replace type ="date" by type="texte", and then i type the date manual, everything goes fine.  U have the code below.

Any idea ?  

transactionForm.html  :

<!DOCTYPE html>
<title>Add a transaction</title>
<link rel="stylesheet" href="/bootstrap-4.0.0/css/bootstrap.min.css" />

Add a transaction

        <div class="container">
                <form action="#" th:action="@{/transactions/add}" th:object="${transaction}"
                        <div class="form-group">
                                <label for="transactionDate">Transaction Date :</label>
                                <input id="transactionDate" class="form-control" type="date" th:field="*{date}" />
                        <button type="submit" class="btn btn-primary">Submit</button>

Class Java Transaction :

public class Transaction {
        private Long id;

        @DateTimeFormat(pattern = "dd/MM/yyyy")
        private Date date;


Controller  :

        public String transactionForm(Model model) {
                model.addAttribute("transaction", new Transaction());
                return "transactionForm";

        public String createTransaction(@ModelAttribute Transaction transaction) {
                return "redirect:/transactions";