com.scooterframework.orm.activerecord
Class ModelValidators

java.lang.Object
  extended by com.scooterframework.common.validation.Validators
      extended by com.scooterframework.orm.activerecord.ModelValidators

public class ModelValidators
extends Validators

ModelValidators contains validation methods to validate a model record.

Subclass of ActiveRecord may override one or more of the following methods in order to use validations:

To use a different ModelValidators class, subclass of ActiveRecord must override validators() method.

 Examples:
      public class Post extends ActiveRecord {
            public void registerRelations() {
                belongsTo(Topic.class, "mapping: topic_id=id; counter_cache: true");
                belongsTo(User.class, "mapping: user_id=id; counter_cache: true");
            }

            public void validatesRecord() {
                validators().validatesPresenceOf("body");
                validators().validatesLengthMaximum("body", 10000);
            }
        }
 


Field Summary
protected  ActiveRecord record
          The current record instance.
 
Fields inherited from class com.scooterframework.common.validation.Validators
ACCEPTED, CANNOT_BE_BLANK, CANNOT_BE_NULL, CONFIRMATION, EMAIL_PATTERN, EXCEEDING_MAXIMUM, EXCLUSION, INCLUSION, IS_EMAIL, IS_EQUALTO, IS_INSIDE, IS_LARGERTHAN, IS_LARGERTHAN_OR_EQUALTO, IS_LESSTHAN, IS_LESSTHAN_OR_EQUALTO, IS_UNIQUE, IS_WITHIN, NOT_A_NUMBER, OUTOF_RANGE, TOO_LONG, TOO_SHORT, WRONG_LENGTH
 
Constructor Summary
ModelValidators(ActiveRecord record)
          Construct a validator.
 
Method Summary
protected  java.lang.Object getData(java.lang.String fieldName)
          Returns value for the specific fieldName of the underlying record.
protected  ValidationResults getValidationResults()
          Returns validation results.
 void validatesUniqenessOf(java.lang.String columnNames, java.lang.String messageKey)
          Validates each field data is unique.
 
Methods inherited from class com.scooterframework.common.validation.Validators
validatesAcceptanceOf, validatesAcceptanceOf, validatesAcceptanceOf, validatesConfirmationOf, validatesConfirmationOf, validatesConfirmationOf, validatesConfirmationOf, validatesExclusionOf, validatesExclusionOf, validatesExclusionOf, validatesInclusionOf, validatesInclusionOf, validatesInclusionOf, validatesIsEmail, validatesIsEmail, validatesIsNumber, validatesIsNumber, validatesLengthInRangeOf, validatesLengthInRangeOf, validatesLengthMaximum, validatesLengthMaximum, validatesLengthMinimum, validatesLengthMinimum, validatesLengthOf, validatesLengthOf, validatesNotNull, validatesNotNull, validatesNumberIsEqualTo, validatesNumberIsEqualTo, validatesNumberIsInsideRangeOf, validatesNumberIsInsideRangeOf, validatesNumberIsLargerThan, validatesNumberIsLargerThan, validatesNumberIsLargerThanOrEqualTo, validatesNumberIsLargerThanOrEqualTo, validatesNumberIsLowerThan, validatesNumberIsLowerThan, validatesNumberIsLowerThanOrEqualTo, validatesNumberIsLowerThanOrEqualTo, validatesNumberIsWithinRangeOf, validatesNumberIsWithinRangeOf, validatesNumberMaximum, validatesNumberMaximum, validatesPresenceOf, validatesPresenceOf, validatesPresenceOf, validatesPresenceOf, validatesUniqenessOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

record

protected ActiveRecord record

The current record instance.

Constructor Detail

ModelValidators

public ModelValidators(ActiveRecord record)

Construct a validator.

Parameters:
record - an ActiveRecord instance
Method Detail

validatesUniqenessOf

public void validatesUniqenessOf(java.lang.String columnNames,
                                 java.lang.String messageKey)
Validates each field data is unique.

Overrides:
validatesUniqenessOf in class Validators
Parameters:
columnNames - A string of column names separated by comma or blank
messageKey - key to the message in MessagesResources file

getValidationResults

protected ValidationResults getValidationResults()
Returns validation results.

Specified by:
getValidationResults in class Validators
Returns:
validation results

getData

protected java.lang.Object getData(java.lang.String fieldName)
Returns value for the specific fieldName of the underlying record.

Specified by:
getData in class Validators
Parameters:
fieldName -
Returns:
value for the field