I am writing simple CRUD(Create, Remove ,Update ,Delete) application using Spring MVC and hibernate.
In Create i can add membership start date in MM/dd/yyyy format.
In Update i want the same data to be display(populate) in my jsp.
My problem is at the time of update my date input field is showing date in yyyy-MM-dd format.
I find out the solution for this
At the time of getting values(in my model’s getter method) ,i have written one small code as below:
public Date getDateOfIncorporation() {
Date date=null;
try {
Date abc = this.dateOfIncorporation;
if (abc != null) {
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String formattedDate = df.format(abc);
date= df.parse(formattedDate);
}
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
but i am confused about my approach .
is this the right way or am i doing any mistake by writing this code in form(model) .???
since i want to maintain good coding standard , i need your suggestions on the same.
is this acceptable , if any senior reviews my code …??
actually it should be done in the view (i.e. your jsp) have a look at the JSTL format taglib:
and especially its pattern attribute (e.g.
pattern="MM/dd/yyyy")