You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eddie Yan <ed...@streamyx.com> on 2004/06/26 13:24:23 UTC
[OT] Storing Birth Date
Anyone know what is the best practices to store a person
date of birth ? How should we design our detail object, JSP and database
in such way we don't have a messy approached to populate the day,
month and year in Action class to be able to display in JSP during UPDATE
process.
Currently, I have a JSP with combo box for day, month and year.
Using mySQL db, I set the dateOfBirth column to TIMESTAMP.
(Some told me to use DATE for this column).
Obviously TIMESTAMP have the limitation since date of birth before
Jan 1 1970 will be stored as 00000000000. Know any workaround
to this one ?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Storing Birth Date
Posted by Eddie Yan <ed...@streamyx.com>.
Thanks for the input Mark.
This approach seems OK to me.
What is the column you use to store dob ?
We need to specify in the repository_user.xml the data type
for this column.
Ed.
----- Original Message -----
From: "Mark Lowe" <ma...@boxstuff.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Saturday, June 26, 2004 8:05 PM
Subject: Re: [OT] Storing Birth Date
> I do string - calendar conversion in an action form, its gets and sets
> strings modifying a calendar object which can be then given to the
> action ready to be saved back to the model.
>
> private Calendar dob = Calendar.getInstance();
>
> public String getDayOfBirth() {
> int dayInt = dob.get(Calendar.DAY_OF_MONTH);
> return Integer.parseInt(dayInt);
> }
>
> public void setDayOfBirth(String month) {
> int monthInt = Integer.parseInt(month);
> this.dob.set(Calendar.DAY_OF_MONTH,monthInt);
> }
>
> public Calendar getDob() {
> return dob;
> }
>
> public void setCalendar(Calendar dob) {
> this.dob = dob;
> }
>
> I should warn you that you need to validate input in a validate method
> to in case the day is out of range for the given calendar month. Unless
> you generate your select menus when the user changes the month and
> year.
>
> Some folk will frown upon such practice and claim its not MVC, I could
> be wrong but I disagree. And also gets the action form doing a little
> more work.
>
>
>
> Mark
>
> On 26 Jun 2004, at 13:24, Eddie Yan wrote:
>
> > Anyone know what is the best practices to store a person
> > date of birth ? How should we design our detail object, JSP and
> > database
> > in such way we don't have a messy approached to populate the day,
> > month and year in Action class to be able to display in JSP during
> > UPDATE
> > process.
> >
> > Currently, I have a JSP with combo box for day, month and year.
> > Using mySQL db, I set the dateOfBirth column to TIMESTAMP.
> > (Some told me to use DATE for this column).
> >
> > Obviously TIMESTAMP have the limitation since date of birth before
> > Jan 1 1970 will be stored as 00000000000. Know any workaround
> > to this one ?
> >
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Storing Birth Date
Posted by Mark Lowe <ma...@boxstuff.com>.
I do string - calendar conversion in an action form, its gets and sets
strings modifying a calendar object which can be then given to the
action ready to be saved back to the model.
private Calendar dob = Calendar.getInstance();
public String getDayOfBirth() {
int dayInt = dob.get(Calendar.DAY_OF_MONTH);
return Integer.parseInt(dayInt);
}
public void setDayOfBirth(String month) {
int monthInt = Integer.parseInt(month);
this.dob.set(Calendar.DAY_OF_MONTH,monthInt);
}
public Calendar getDob() {
return dob;
}
public void setCalendar(Calendar dob) {
this.dob = dob;
}
I should warn you that you need to validate input in a validate method
to in case the day is out of range for the given calendar month. Unless
you generate your select menus when the user changes the month and
year.
Some folk will frown upon such practice and claim its not MVC, I could
be wrong but I disagree. And also gets the action form doing a little
more work.
Mark
On 26 Jun 2004, at 13:24, Eddie Yan wrote:
> Anyone know what is the best practices to store a person
> date of birth ? How should we design our detail object, JSP and
> database
> in such way we don't have a messy approached to populate the day,
> month and year in Action class to be able to display in JSP during
> UPDATE
> process.
>
> Currently, I have a JSP with combo box for day, month and year.
> Using mySQL db, I set the dateOfBirth column to TIMESTAMP.
> (Some told me to use DATE for this column).
>
> Obviously TIMESTAMP have the limitation since date of birth before
> Jan 1 1970 will be stored as 00000000000. Know any workaround
> to this one ?
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Storing Birth Date
Posted by Michael McGrady <mi...@michaelmcgrady.com>.
There are lots of ways to do this, of course, but I have found over the
years that working from a long value works best for me. From there you can
go any direction.
Michael
At 09:46 AM 6/26/2004, Rick Reumann wrote:
>Eddie Yan wrote:
>
>>Anyone know what is the best practices to store a person
>>date of birth ? How should we design our detail object, JSP and database
>>in such way we don't have a messy approached to populate the day,
>>month and year in Action class to be able to display in JSP during UPDATE
>>process.
>>Currently, I have a JSP with combo box for day, month and year.
>>Using mySQL db, I set the dateOfBirth column to TIMESTAMP.
>>(Some told me to use DATE for this column).
>
>I tend to do it slightly different than Mark's approach or yours above
>using combo boxes. I like to let the user be able to free form type in the
>date and also provide the option of calendar date picker (plenty of free
>javascript ones out there). I hate having to select each part of the date
>from a drop down since I can type in a date pretty quickly (If the user
>hates typing that's what the calendar picker is for).
>
>I usually put the format I want next to the date field in the JSP as
>defined as bean message property that can be looked up in the
>ApplicationResources file (ie form.date.format=mm/dd/yy ). Not only is
>this good in case you want to deal with localization issues, but it's nice
>if someone comes to you and says "Product Manager John Doe would rather
>the user's enter the date as mm-dd-yyyy instead of mm/dd/yy"
>
>The form field I take is a simple String. I then validate using the
>validator framework or simply validate in the Action itself. (If you use
>the validator framework you have to register your date converter, but once
>registered it's set for the whole application so you only do it once. If
>you want to go that route I can show you how to do it.. there are some
>posts in the archives here how to do it also). When needing to display the
>date back in the form it's just as easy when you have that converter
>registered since BeanUtils can convert it correctly for you.
>
>I like the flexibility of this approach. I can see the benefit also of
>having the ActionForm return the Date formats you want, but it's not my
>preferred way of doing it.
>
>
>--
>Rick
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Storing Birth Date
Posted by Rick Reumann <st...@reumann.net>.
Eddie Yan wrote:
> Anyone know what is the best practices to store a person
> date of birth ? How should we design our detail object, JSP and database
> in such way we don't have a messy approached to populate the day,
> month and year in Action class to be able to display in JSP during UPDATE
> process.
>
> Currently, I have a JSP with combo box for day, month and year.
> Using mySQL db, I set the dateOfBirth column to TIMESTAMP.
> (Some told me to use DATE for this column).
I tend to do it slightly different than Mark's approach or yours above
using combo boxes. I like to let the user be able to free form type in
the date and also provide the option of calendar date picker (plenty of
free javascript ones out there). I hate having to select each part of
the date from a drop down since I can type in a date pretty quickly (If
the user hates typing that's what the calendar picker is for).
I usually put the format I want next to the date field in the JSP as
defined as bean message property that can be looked up in the
ApplicationResources file (ie form.date.format=mm/dd/yy ). Not only is
this good in case you want to deal with localization issues, but it's
nice if someone comes to you and says "Product Manager John Doe would
rather the user's enter the date as mm-dd-yyyy instead of mm/dd/yy"
The form field I take is a simple String. I then validate using the
validator framework or simply validate in the Action itself. (If you use
the validator framework you have to register your date converter, but
once registered it's set for the whole application so you only do it
once. If you want to go that route I can show you how to do it.. there
are some posts in the archives here how to do it also). When needing to
display the date back in the form it's just as easy when you have that
converter registered since BeanUtils can convert it correctly for you.
I like the flexibility of this approach. I can see the benefit also of
having the ActionForm return the Date formats you want, but it's not my
preferred way of doing it.
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Storing Birth Date
Posted by Jorge Salido <js...@gmail.com>.
I would certainly not use timestamps. A timestamp is certainly useful
when you want to record current time (like a snapshot), but not past
dates. And even then be aware of timestamps... And anyway, since
timestamp also contains time data, it is not being efficient (at least
by that standard). Cetainly, you could create some classes to
artificially handle timestamps and support other dates, but why
bother? Sound very improductive and problematic than what you can get
out of it...
Other than that, how you store the date is your call. I usually prefer
handling dates as numeric values, and using a YYYYMMDD format, so they
can easily be sorted. But that's just me. If you rely on any tools for
persistence, use what will suit them. If you depend on the database
for date operations, use whatever date format the db provides
natively. In any case, it depends more in which one will prove to be
more comfortable for you in the long run.
BTW, on the client side, I highly recommend you to try this calendar
picker script (javascript)
http://dynarch.com:1979/mishoo/calendar.epl
Jorge
On Sat, 26 Jun 2004 19:24:23 +0800, Eddie Yan <ed...@streamyx.com> wrote:
> Anyone know what is the best practices to store a person
> date of birth ? How should we design our detail object, JSP and database
> in such way we don't have a messy approached to populate the day,
> month and year in Action class to be able to display in JSP during UPDATE
> process.
>
> Currently, I have a JSP with combo box for day, month and year.
> Using mySQL db, I set the dateOfBirth column to TIMESTAMP.
> (Some told me to use DATE for this column).
>
> Obviously TIMESTAMP have the limitation since date of birth before
> Jan 1 1970 will be stored as 00000000000. Know any workaround
> to this one ?
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org