You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Suresh Addagalla <su...@wipro.com> on 2003/01/22 11:37:16 UTC
Date Validation: Help Required
Hi,
I haven't been able to successfully use the Validator for doing Date
validations with struts 1.1 b3.
I need to localize the date format. Since Validator would anyway take
the default locale and the SHORT form of the date from the system, I
have decided that I will use the short format in all Locales. But I am
facing the following problems.
1. If I don't specify the "dateFormat" and/or "dateFormatStrict", I am
getting JavaScript errors (msg: length is null or not defined..) in the
2nd line in the code below (from validator-rules.xml)
var datePattern = oDate[x][2]("datePatternStrict");
if ((form[oDate[x][0]].type == 'text' ||
form[oDate[x][0]].type == 'textarea') &&
(value.length > 0) &&
(datePattern.length > 0)) {
var MONTH = "MM";
var DAY = "dd";
var YEAR = "yyyy";
var orderMonth = datePattern.indexOf(MONTH);
var orderDay = datePattern.indexOf(DAY);
var orderYear = datePattern.indexOf(YEAR);
2. Validator seems to be using a fixed date format (last 6 lines in the
code above). How can the JavaScript take care of other locales/formats?
Do I need to change the JavaScript per installation basis or Do I need
to download a different version of struts jar? What exactly is required
to achieve localization.
IMP: As far as possible, I would like to avoid specifying the
"dateFormat"/"dateFormatStrict" in validator-rules.xml since I want to
use the default locale's SHORT form.
Thanks,
Suresh
Re: Date Localization
Posted by Gemes Tibor <ti...@i-trade.hu>.
2003. január 23. 07:31 dátummal Suresh Addagalla ezt írtad:
> Sorry to repost, but I didn't get any replies so far :(
>
> Hi,
>
> I haven't been able to successfully use the Validator for doing Date
> validations with struts 1.1 b3.
>
> I need to localize the date format. Since Validator would anyway take
> the default locale and the SHORT form of the date from the system, I
> have decided that I will use the short format in all Locales. But I am
> facing the following problems.
You cannot parse the date client side as you don't know the current locale the
client has choosen and if you knew you couldn't find out the date pattern for
the locale either. So you do not have pattern to match with.
Remove the javascript section from validator-rules.xml since it works only if
you specify datePatternStrict. If you remove it, the validation will occur
server side only. And server-side validation uses the current client locale's
date format, afaik.
Hth,
Tib
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>