Validation Being Called Twice
Jeff Dunnett <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello Everyone,
I have a validation method:
public String validateHPostal(String value) throws
NSValidation.ValidationException {
logger.debug("Value - " + value);
String str = value;
logger.debug("String - " + str);
/*Pattern.matches("[A-Z][0-9][A-Z][0-9][A-Z][0-9]",
value.subSequence(0, value.length())) */
if (str == null || str.length() == 0 ){
logger.debug("Value is null so we are throwing exception");
logger.debug(value);
throw new NSValidation.ValidationException("PostalCode cannot be
left blank.");
}else if( Pattern.matches("[A-Z][0-9][A-Z][0-9][A-Z][0-9]",
str.subSequence(0, str.length()))){
logger.debug("The string matches a Canadian postal code");
return str = str.substring(0,3) + " " + str.substring(3,6);
}else if(Pattern.matches("[A-Z][0-9][A-Z] [0-9][A-Z][0-9]",
str.subSequence(0, str.length())) || Pattern.matches("[0-9]{5}(-[0-9]
{4})?", str.subSequence(0, str.length()))){
logger.debug("The string is a Postal Code or Zip Code");
return str;
}else{
logger.debug("We are throwing an exception because the
registrant did not provide a valid Canadian postal code");
throw new NSValidation.ValidationException("You must
provide a valid Canadian postal code or American zip code");
}
}
I have a saveChanges call in a block such as this:
try{
//Resetting the error message before attempting to
set the registration.
s.setErrorMessage("");
ec.saveChanges();
logger.debug("No exception generated");
}catch(Exception e){
logger.debug("We have caught an exception");
logger.debug(e);
s.setErrorMessage(e.getMessage());
ec.revert();
return null;
}
The when I try to call the validation method validateHPostal with
value = 4345 (data that is supposed to throw an exception) it is
almost as if the validation is being called twice. My log shows:
2007-02-14 11:23:10,890 [WorkerThread3] DEBUG Registrant - Value - 4345
2007-02-14 11:23:10,891 [WorkerThread3] DEBUG Registrant - String - 4345
2007-02-14 11:23:10,891 [WorkerThread3] DEBUG Registrant - We are
throwing an exception because the registrant did not provide a valid
Canadian postal code
[2007-02-14 11:23:10 EST] <WorkerThread3> Validation failed on an
object [java.lang.String] with keypath = registrant.hPostal and
exception: You must provide a valid Canadian postal code or American
zip code
[2007-02-14 11:23:10 EST] <WorkerThread3> Validation failed on an
object [null] with keypath = aGuest.firstName and exception: the
first name field cannot be left blank.
[2007-02-14 11:23:10 EST] <WorkerThread3> Validation failed on an
object [null] with keypath = aGuest.lastName and exception: the last
name field cannot be left blank.
2007-02-14 11:23:10,961 [WorkerThread3] DEBUG Registrant - Value - null
2007-02-14 11:23:10,962 [WorkerThread3] DEBUG Registrant - String - null
2007-02-14 11:23:10,962 [WorkerThread3] DEBUG Registrant - Value is
null so we are throwing exception
2007-02-14 11:23:10,962 [WorkerThread3] DEBUG Registrant -
2007-02-14 11:23:10,980 [WorkerThread3] DEBUG RegistrationPage - We
have caught an exception
2007-02-14 11:23:10,981 [WorkerThread3] DEBUG RegistrationPage -
com.webobjects.foundation.NSValidation$ValidationException:
PostalCode cannot be left blank.
It seems as if the objects is ran through validation twice the first
tim throws these exception:
[2007-02-14 11:23:10 EST] <WorkerThread3> Validation failed on an
object [java.lang.String] with keypath = registrant.hPostal and
exception: You must provide a valid Canadian postal code or American
zip code
[2007-02-14 11:23:10 EST] <WorkerThread3> Validation failed on an
object [null] with keypath = aGuest.firstName and exception: the
first name field cannot be left blank.
[2007-02-14 11:23:10 EST] <WorkerThread3> Validation failed on an
object [null] with keypath = aGuest.lastName and exception: the last
name field cannot be left blank.
Then since the validateHPostal is now passed is throws this exception:
2007-02-14 11:23:10,981 [WorkerThread3] DEBUG RegistrationPage -
com.webobjects.foundation.NSValidation$ValidationException:
PostalCode cannot be left blank.
It should only be throwing this exception:
[2007-02-14 11:23:10 EST] <WorkerThread3> Validation failed on an
object [java.lang.String] with keypath = registrant.hPostal and
exception: You must provide a valid Canadian postal code or American
zip code
Does anyone have any idea as to what might be causing the unusual
behaviour?
Regards,
Jeff
_______________________________________________
WebObjects-dev mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/webobjects-dev