From: "Dan Bachelder" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, September 02, 2001 1:31 PM
Subject: dates...
> dates on peers dataobjects...
>
> when i do:
>
> <input type="hidden" name="createStamp" value="$note.createStamp"/>
>
> my html source looks good i see "2001-09-01 23:22:59.0"
>
> then in my action:
>
> data.getParameters().setProperties( note );
>
> I get all the String and Integer fields set correctly but the createStamp
> date field is null...
>
> what am I doing wrong? how should date fields be handled?
In my OM generated class I usually add a wrapper class that allows me
to retrieve the date as a formatted String and another wrapper that parses
the input string thus:
/**
* A wrapper around <code>endDate</code>.
*/
public String getEndDateString()
{
return CommonFunctions.dateToString(getEndDate());
}
/**
* A wrapper around <code>endDate</code>.
*/
public void setEndDateString(String dateString)
{
setEndDate(CommonFunctions.stringToDate(dateString));
}
------------- CommonFunctions -------------
public static String dateToString(Date date)
{
return CommonConstants.DATE_FORMAT.format(date);
}
public static Date stringToDate(String dateString)
{
ParsePosition pos = new ParsePosition(0);
return CommonConstants.DATE_FORMAT.parse(dateString, pos);
}
------------- CommonConstants --------------------
public static final SimpleDateFormat DATE_FORMAT = new
SimpleDateFormat("d/MM/yyyy");
I then use Intake with the following rules:
<field name="EndDate" key="edate" type="String" mapToProperty="EndDateString">
<rule name="required" value="true">Please enter an end date.</rule>
<rule name="mask" value="^[0-3]?\d/[01]?\d/[29][09]\d\d$">Please enter a sensible
date ("dd/mm/yyyy").</rule>
</field>
Note the use of Australian date formats throughout. The
validation is kind of quirky, but it seems to work well enough.
There is also the DateSelector class which is kind of cool. In
tdk 2.1, ParameterParser contains some smarts to pull together
the day, month and year components that DateSelector generates
to make it really easy to use. I haven't tried to hook this up to
Intake yet, but it shouldn't be too difficult. The only problem
is that the smarts in ParameterParser have been ripped out in
turbine 3.0. This is a shame because this is harder piece of the
puzzle (generating the three inputs could easily be done with
a velocimacro, but bringing the parts back together into a
single Date will have to be done somehow else). Anyone
working on turbine 3 care to comment?
HTH
Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]