You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Raible, Matt" <Ma...@cable.comcast.com> on 2003/04/17 19:22:40 UTC
RE: [validator] validating that date is at least 5 business
days from today
Here's what I wrote in my validate() method of my form:
// Validate that desiredComplete date is at least 5 business days in
the future
Date desiredDate = null;
try {
// Convert date String to a Date
desiredDate =
DateUtil.convertStringToDate(crForm.getDesiredCompleteDate());
} catch (ParseException pe) {
pe.printStackTrace();
}
Calendar desired = new GregorianCalendar();
desired.setTime(desiredDate);
Calendar now = new GregorianCalendar();
// verify that the desired date is at more than 5 days from today
if ((desired.get(Calendar.DATE) - now.get(Calendar.DATE)) <= 5) {
errors.add("desiredCompleteDate",
new ActionError("errors.desiredDate.5days",
crForm.getDesiredCompleteDate()));
} else { // check that desired is not on a weekend
if ((desired.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
|| (desired.get(Calendar.DAY_OF_WEEK) ==
Calendar.SUNDAY)) {
errors.add("desiredCompleteDate",
new ActionError("errors.desiredDate.weekend",
crForm.getDesiredCompleteDate()));
}
}
Mark - I wrote the following JavaScript function to catch errors on the
client side - seems to work fairly well - thanks for the inspiration. Too
bad I can't seem to hook this into the validator's JavaScript messages (one
big alert box).
function validateDesiredDate(theForm) {
// Validate that desiredComplete date is at least 5 business days in
the future
var dateField = theForm.desiredCompleteDate;
// parse MM/dd/yyyy to create a Date object
var desired = parseDate(dateField.value);
var now = new Date();
// verify that the desired date is at more than 5 days from today
if ((desired.getDate() - now.getDate()) <= 5) {
dateField.focus();
alert("The desired complete date ("+dateField.value+") must be
at least 5 business days from today.");
return false;
} else { // check that desired is not on a weekend
if (desired.getDay() == 0 || desired.getDay() == 6) {
dateField.focus();
alert("The desired complete date ("+dateField.value+") must
be a business day (Mon-Fri), rather than a weekend day.");
return false;
}
}
return true;
}
Thanks,
Matt
> -----Original Message-----
> From: Wendy Smoak [mailto:Wendy.Smoak@asu.edu]
> Sent: Thursday, April 17, 2003 10:47 AM
> To: 'Struts Users Mailing List'
> Subject: RE: [validator] validating that date is at least 5 business
> days from day
>
>
> Matt:
> > Just wondering if the validator had this built in - I've
> already wrote
> a
> > custom validator in my validate(), but wanted to make sure I was
> > re-inventing the wheel.
>
> Sounds like you're talking about doing it in the 'validate'
> method, and
> I'm
> talking about using the Validator plug-in and configuring a custom
> validator
> in the validation.xml file.
>
> Either way, would you please share the Java code that does this
> validation?
> I'm sure it could be useful to someone searching the archives in the
> future,
> and I'm interested in eliminating the extra database calls
> that I'm not
> doing to get my own date validation to work. I've never been
> successful
> convincing the Java Date/Calendar classes to do what I want
> them to, but
> maybe a good example will clear up my confusion.
>
> Thanks,
>
> --
> Wendy Smoak
> Applications Systems Analyst, Sr.
> Arizona State University PA Information Resources Management
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [validator] validating that date is at least 5 business days from
today
Posted by Jeff Smith <je...@centralscheduling.net>.
What? You're not checking for stat holidays too? :-)
Jefficus
----- Original Message -----
From: "Raible, Matt" <Ma...@cable.comcast.com>
To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
Sent: Thursday, April 17, 2003 11:22 AM
Subject: RE: [validator] validating that date is at least 5 business days
from today
> Here's what I wrote in my validate() method of my form:
>
> // Validate that desiredComplete date is at least 5 business days
in
> the future
> Date desiredDate = null;
>
> try {
> // Convert date String to a Date
> desiredDate =
>
> DateUtil.convertStringToDate(crForm.getDesiredCompleteDate());
> } catch (ParseException pe) {
> pe.printStackTrace();
> }
>
> Calendar desired = new GregorianCalendar();
> desired.setTime(desiredDate);
>
> Calendar now = new GregorianCalendar();
>
> // verify that the desired date is at more than 5 days from today
> if ((desired.get(Calendar.DATE) - now.get(Calendar.DATE)) <= 5) {
> errors.add("desiredCompleteDate",
> new ActionError("errors.desiredDate.5days",
> crForm.getDesiredCompleteDate()));
> } else { // check that desired is not on a weekend
>
> if ((desired.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
> || (desired.get(Calendar.DAY_OF_WEEK) ==
> Calendar.SUNDAY)) {
> errors.add("desiredCompleteDate",
> new ActionError("errors.desiredDate.weekend",
>
> crForm.getDesiredCompleteDate()));
> }
> }
>
>
> Mark - I wrote the following JavaScript function to catch errors on the
> client side - seems to work fairly well - thanks for the inspiration. Too
> bad I can't seem to hook this into the validator's JavaScript messages
(one
> big alert box).
>
> function validateDesiredDate(theForm) {
> // Validate that desiredComplete date is at least 5 business days
in
> the future
> var dateField = theForm.desiredCompleteDate;
>
> // parse MM/dd/yyyy to create a Date object
> var desired = parseDate(dateField.value);
> var now = new Date();
>
> // verify that the desired date is at more than 5 days from today
> if ((desired.getDate() - now.getDate()) <= 5) {
> dateField.focus();
> alert("The desired complete date ("+dateField.value+") must be
> at least 5 business days from today.");
> return false;
> } else { // check that desired is not on a weekend
> if (desired.getDay() == 0 || desired.getDay() == 6) {
> dateField.focus();
> alert("The desired complete date ("+dateField.value+")
must
> be a business day (Mon-Fri), rather than a weekend day.");
> return false;
> }
> }
> return true;
> }
>
> Thanks,
>
> Matt
>
> > -----Original Message-----
> > From: Wendy Smoak [mailto:Wendy.Smoak@asu.edu]
> > Sent: Thursday, April 17, 2003 10:47 AM
> > To: 'Struts Users Mailing List'
> > Subject: RE: [validator] validating that date is at least 5 business
> > days from day
> >
> >
> > Matt:
> > > Just wondering if the validator had this built in - I've
> > already wrote
> > a
> > > custom validator in my validate(), but wanted to make sure I was
> > > re-inventing the wheel.
> >
> > Sounds like you're talking about doing it in the 'validate'
> > method, and
> > I'm
> > talking about using the Validator plug-in and configuring a custom
> > validator
> > in the validation.xml file.
> >
> > Either way, would you please share the Java code that does this
> > validation?
> > I'm sure it could be useful to someone searching the archives in the
> > future,
> > and I'm interested in eliminating the extra database calls
> > that I'm not
> > doing to get my own date validation to work. I've never been
> > successful
> > convincing the Java Date/Calendar classes to do what I want
> > them to, but
> > maybe a good example will clear up my confusion.
> >
> > Thanks,
> >
> > --
> > Wendy Smoak
> > Applications Systems Analyst, Sr.
> > Arizona State University PA Information Resources Management
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org