Re: Validation Being Called Twice

David Wetzel <[email protected]>
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
Jeff Dunnett wrote:

> I have a validation method:

(...)

> 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?

It looks like you have told EOF that your firstName and lastName cannot be NULL.
After your form is posted, WO will call validateTakeValueForKey (maybe a bit different spelling) which 
will do the validation for every key in your EO.

Once you save your EditingContext those validating is done again.

Set a breakpoint in your validation code and print the back trace.

HTH

Dave

-- 
   _  _
 _(_)(_)_  David Wetzel, Turbocat's Development,
(_) __ (_) Buchhorster Strasse 23, D-16567 Muehlenbeck/Berlin, FRG,
  _/  \_   Fax +49 33056 82835 Phone +49 33056 82834
 (______)  http://www.turbocat.de/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.