Re: ValidationException, need help
Re: ValidationException, need help
- Subject: Re: ValidationException, need help
- From: "Jerry W. Walker" <email@hidden>
- Date: Thu, 21 Apr 2005 09:37:41 -0400
On Apr 21, 2005, at 5:10 AM, Amedeo Mantica wrote:
as suuggested in some books or online, i create a method like this....
public String validateAttibbute(String Attribute) throws
NSValidation.ValidationException
{
if(Attribute....code for checking...)
{
//code if attribute is OK
}
else
{
String errorString = "Attribute is BAD";
throw new NSValidation.ValidatioException(errorString);
}
}
First, this should be a method implemented in your EOCustomObject. As
Florijan suggested in another reply, the argument attribute should have
the type Object, since, from the perspective of your EO, you have no
idea what kind of raw data they're going to throw at you for a new
value. You may know initially, but some future use of your EO could
fool you.
This method should be called automatically, but....is not called!..
also who passes the arguments to my method?
If you look up validateValueForKey in the NSValidation JavaDoc, it says:
The default implementation of this method (provided by
NSValidation.DefaultImplementation) checks for a method of the
form
validateKey (for example, validateBudget for a key of "budget").
If such
a method exists, it invokes it and returns the result. Thus,
NSValidation
objects can implement individual validateKey methods to check
limits,
test for nonsense values, and coerce values (convert strings to
dates
or numbers, for example). If no such method exists, it simply
returns
the value
The validateValueForKey method is invoked indirectly by EOCustomObject
for each attribute key in your EO. From EOCustomObject JavaDoc: "This
method [validateValueForKey] is responsible for two things: coercing
the value into an appropriate type for the object, and validating it
according to the object's rules."
When you execute anEditingContext.saveChanges(), the editing context
invokes several validation methods (validateForInsert,
validateForUpdate, etc.) which invoke validateForSave() by default.
Quoting the JavaDoc for EOCustomObject's validatedForSave:
EOCustomObject's implementation sends the receiver's
EOClassDescription a validateObjectForSave message, then iterates
through all of the receiver's properties. If this results in
more than one
exception, the Exception returned contains the additional ones
in its
userInfo dictionary under
NSValidation.ValidationException.AdditionalExceptionsKey.
Subclasses should invoke super's implementation before performing
their own validation, and should combine any Exception thrown by
super's implementation with their own.
Jerry
--
__ Jerry W. Walker, Partner
C o d e F a b, LLC - "High Performance Industrial Strength Internet
Enabled Systems"
email@hidden
212 465 8484 X-102 office
212 465 9178 fax
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden