Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring mvc date format with form:input

Tags:

I have hibernate entity and a bean:

@Entity
public class GeneralObservation {
    @DateTimeFormat(pattern = "dd/MM/yyyy")
    Date date;

    @Column
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
}

also I have

@InitBinder
protected void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(
            dateFormat, false));
}

and

        form:input
                id = "datepicker"
                name="date"
                itemLabel="date"
                path="newObservation.date"

When I go to my url I see:

my form

How can I force it to have mm/DD/yyyy format? Thanx

like image 228
Stepan Yakovenko Avatar asked Aug 10 '13 15:08

Stepan Yakovenko


1 Answers

You can use fmt:formatDate jstl tag:

<fmt:formatDate value="${yourObject.date}" var="dateString" pattern="dd/MM/yyyy" />
<form:input path="date" value="${dateString} .. />
like image 83
yname Avatar answered Sep 21 '22 15:09

yname