Date or String declaration in a javabean
Posted
by Jeff
on Stack Overflow
See other posts from Stack Overflow
or by Jeff
Published on 2010-06-07T17:31:17Z
Indexed on
2010/06/07
17:32 UTC
Read the original article
Hit count: 169
Should I declare an attribute in a javabean that holds a date value a user types in on an HTML form as a String or Date?
I feel I should declare as a Date, however, since I do server validation on all form data, if the date doesn't validate, when I pass the form bean back to the jsp view for correcting, I lose the date value that the user tried to type in.
If I declare as a String, if the date doesn't validate, I'm able to set the string value in the bean and pass the bean back to the view and the user can see what they incorrectly typed.
But with a String declaration for Date inputs I forsee problems down the road with my DAO. I want to be able to use a DAO utility which generates a prepare statement using setObject.
In my html form I request dates to be mm/dd/yyyy and in DAO i'm using Oracle Date. I can not use hibernate or such, since this is a corporate intranet.
What is the best practice "pattern" I should be following??
© Stack Overflow or respective owner