RE: Accepting multiple date masks with the date validator

2006-08-03 Thread Adam Gordon
IIOC, the only way you can do this with the stock validator is to use mask
rather than date as the validator.  Then, you can use a regex to dictate
your mask.  I'll warn you though, if you use a regular expression it's going
to be VERY long because it will also need to validate that the date entered
is valid.  Additionally, the stock date validator accepts dates like 30 FEB
 and just rolls it to the appropriate March date.  Here's the REGEX we
use (note that the regex is all on one line with no spaces:

var
  var-namemask/var-name
 
var-value^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(2
9|30)|(0?[13578]|1[02])/31)/(20)((0[6-9])|(10))|0?2/29/((20)(0[48])))$/var-
value
/var

Alternatively, you can override the validate method in your ValidatorForm
and do it yourself - which given your requirements, sounds like the easier
of the two options.

-Adam


-Original Message-
From: Scott Van Wart [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 02 August 2006 14:59
To: user@struts.apache.org
Subject: Accepting multiple date masks with the date validator

I have a requirement in my project that I be able to accept two 
different date masks.  One with slashes (thus, 10 characters) and one 
without (8 digits).  Is there any way to do this with the stock date 
validator, or do I need to roll my own wrapper?

Thanks,
  Scott

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Accepting multiple date masks with the date validator

2006-08-03 Thread Scott Van Wart

Adam Gordon wrote:

IIOC, the only way you can do this with the stock validator is to use mask
rather than date as the validator.  Then, you can use a regex to dictate
your mask.  I'll warn you though, if you use a regular expression it's going
to be VERY long because it will also need to validate that the date entered
is valid.  Additionally, the stock date validator accepts dates like 30 FEB
 and just rolls it to the appropriate March date.  Here's the REGEX we
use (note that the regex is all on one line with no spaces:

var
  var-namemask/var-name
 
var-value^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(2

9|30)|(0?[13578]|1[02])/31)/(20)((0[6-9])|(10))|0?2/29/((20)(0[48])))$/var-
value
/var

Alternatively, you can override the validate method in your ValidatorForm
and do it yourself - which given your requirements, sounds like the easier
of the two options.
  

Holy lipton that's nuts.  I think I'll see what's behind door number 3:

public void setDate( String date )
{
 this.date = translateDate( date ); // where translateDate inserts the 
slashes if necessary

}

So I can use the date validator with no problems, and when the client 
submits the form, they get back a slash-separated date in the input field.


Thanks for the help :)

- Scott


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Accepting multiple date masks with the date validator

2006-08-03 Thread Monkeyden

HAHA!  I would have done the same thing.  I don't want things like that
(regexp) creeping around my application, even if I do only have to touch it
once.  Ech!  shivers

On 8/3/06, Scott Van Wart [EMAIL PROTECTED] wrote:


Adam Gordon wrote:
 IIOC, the only way you can do this with the stock validator is to use
mask
 rather than date as the validator.  Then, you can use a regex to
dictate
 your mask.  I'll warn you though, if you use a regular expression it's
going
 to be VERY long because it will also need to validate that the date
entered
 is valid.  Additionally, the stock date validator accepts dates like 30
FEB
  and just rolls it to the appropriate March date.  Here's the REGEX
we
 use (note that the regex is all on one line with no spaces:

 var
   var-namemask/var-name


var-value^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(2

9|30)|(0?[13578]|1[02])/31)/(20)((0[6-9])|(10))|0?2/29/((20)(0[48])))$/var-
 value
 /var

 Alternatively, you can override the validate method in your
ValidatorForm
 and do it yourself - which given your requirements, sounds like the
easier
 of the two options.

Holy lipton that's nuts.  I think I'll see what's behind door number 3:

public void setDate( String date )
{
this.date = translateDate( date ); // where translateDate inserts the
slashes if necessary
}

So I can use the date validator with no problems, and when the client
submits the form, they get back a slash-separated date in the input field.

Thanks for the help :)

- Scott


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Accepting multiple date masks with the date validator

2006-08-03 Thread Adam Gordon
Heh.  Regular Expressions aren't for everyone - I happen to work w/ two 
engineers who live and die by them.


In your bean setter for the date, I'd make sure no exceptions could be 
thrown, or handle them - the code I took over from an engineer we had 
that left had this issue and it took me almost a week to track down what 
was going on between the validator and his code.


-adam

Scott Van Wart wrote:

Adam Gordon wrote:
IIOC, the only way you can do this with the stock validator is to use 
mask
rather than date as the validator.  Then, you can use a regex to 
dictate
your mask.  I'll warn you though, if you use a regular expression 
it's going
to be VERY long because it will also need to validate that the date 
entered
is valid.  Additionally, the stock date validator accepts dates like 
30 FEB
 and just rolls it to the appropriate March date.  Here's the 
REGEX we

use (note that the regex is all on one line with no spaces:

var
  var-namemask/var-name
 
var-value^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(2 

9|30)|(0?[13578]|1[02])/31)/(20)((0[6-9])|(10))|0?2/29/((20)(0[48])))$/var- 


value
/var

Alternatively, you can override the validate method in your 
ValidatorForm
and do it yourself - which given your requirements, sounds like the 
easier

of the two options.
  

Holy lipton that's nuts.  I think I'll see what's behind door number 3:

public void setDate( String date )
{
 this.date = translateDate( date ); // where translateDate inserts the 
slashes if necessary

}

So I can use the date validator with no problems, and when the 
client submits the form, they get back a slash-separated date in the 
input field.


Thanks for the help :)

- Scott


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Accepting multiple date masks with the date validator

2006-08-03 Thread Scott Van Wart

Adam Gordon wrote:
Heh.  Regular Expressions aren't for everyone - I happen to work w/ 
two engineers who live and die by them.


In your bean setter for the date, I'd make sure no exceptions could be 
thrown, or handle them - the code I took over from an engineer we had 
that left had this issue and it took me almost a week to track down 
what was going on between the validator and his code.
Yeah, essentially I'm covering all the bases (null pointers, index out 
of bounds, etc.) so no RuntimeExceptions can be thrown either.  If 
anything doesn't look right to the translation method, it simply returns 
the original.  I DO like regular expressions, but feel that a lot of 
people go overboard and use them for things they shouldn't be used for :).


- Scott

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]