e keys are evaluated on validateForSave, they don't correspond to properties additionalValidationKeys=("validateEmailPassword"); // This dictionary holds the keys to use for validating properties validateForKey={ // these keys are evaluated on validateForSave, they don't correspond to properties email=( { // this is the message code into ValidationStrings.plist // User.email.wrongLength = "The mail does not have the right size (5 to 50)"; message="wrongLength"; // skip this rule if the value is null ignoreIfNull=true; // if there is a qualifier key, then a dictionary containing "object" and "value" is evaluated // and an exception is thrown if the evaluation returns false qualifier="(value.length >= 5) AND (value.length < 50)"; }, { // again, this is the message code into ValidationStrings.plist message="sampleTest"; // Given this key, an object of the corresponding EOQualifierEvaluation subclass is created // and given this dictionary on creation. This object needs to be re-entrant. className="SampleTest"; // an example is: // public class SampleTest implements EOQualifierEvaluation { // int minLength, maxLength; // public SampleTest(Object param) { // NSDictionary dict=(NSDictionary)param; // minLength=ERXValueUtilities.intValue(dict.objectForKey("minLength")); // maxLength=ERXValueUtilities.intValue(dict.objectForKey("maxLength")); // } // public boolean evaluateObject(Object o) { // ERXEntityClassDescription.ValidationObjectValue val // = (ERXEntityClassDescription.ValidationObjectValue)o; // EOEnterpriseObject eo=val.object(); // String value=(String)val.value(); // return value.length()>= minLength && value.length() <= maxLength; // } // } minLength="5"; maxLength="10"; } ); // This key does not correspond to any property, it get's evaluated in D2WApps where you have a // multi-step page and need to do validation before validateForSave "validateEmailPassword" = ( { message="stupidTestWithEmailAndPassword"; // means to get D2W to highlight the fields involved instead of only displaying the message // For this to work, your corresponding localized String should be // User.email,password.stupidTestWithEmailAndPassword = "Stupid test failed"; keyPaths="email,password"; qualifier="(object.email.length>= object.password.length)"; } ); }; // These get checked when the object gets saved, additionally to "additionalValidations" // The structure of "validateForInsert", "validateForUpdate" and "validateForDelete" is the same. validateForSave = ( { message = "cantBeBoth"; keyPaths = "isEditor,isAdmin"; qualifier = "(object.isEditor = 'Y' and object.isAdmin = 'Y')"; } ); } This code is mainly a quick-and-dirty rewrite from PRValidation by Proteon.
Additionally, this class adds a concept of "Default" values that get pushed into the object at creation time. Simply add a "ERXDefaultValues" key into the entity's userInfo dictionary that contains key-value-pairs for every default you want to set. Alternately, you can set a "default" key on each of the relationship or attrbute's userInfo
Example:
"ERXDefaultValues" = { // Example for simple values. isAdmin = N; isEditor = Y; // Example for a related object (->Languages(pk,displayName)). You need to enter the primary key value. language = "de"; // Example for an NSArray of related objects recommendingUser = "@threadStorage.actor"; // Example for an NSArray articlesToRevisit = "@threadStorage.actor.articles"; // Example for a NSTimestamp. All static methods from ERXTimestampUtilities are supported. created = "@now"; updatePassword = "@tomorrow"; }
If you wish to provide your own class description subclass see the documentation associated with the Factory inner class.