Class ValidateTemplate

java.lang.Object
sunlabs.brazil.template.Template
sunlabs.brazil.sunlabs.ValidateTemplate
All Implemented Interfaces:
TemplateInterface

public class ValidateTemplate extends Template
The ValidateTemplate is designed to validate HTML forms. It performs data validation on sets of properties (e.g. form values) by comparing the values against validation constraints that are specified in other variables.

The "glob" attribute defines the set of variables to be validated, and the "types" attribute maps each variable name matched by "glob" into the variable that names the validation tokens for that variable to be validated. The "types" attribute, which is used to identify the validation types may contain variables of the form, ${n} where 0 < n < 10 which represent the string value matching the nth wildcard in the "glob" attribute.
Example: glob=*.*.*.*.* and types=types.${3}.${1}
will validate a.b.c.d.e against the types contained in types.c.a
The default for types is validate.${1}

For each validate request, all properties matching the specified glob pattern will be validated against pre-loaded validation keys specified by the glob pattern match types. The result will be stored in properties prepended by the prefix attribute, which defaults to the template's prefix.

   <validate glob=pattern [prefix=prepend 
     types=pattern (${1-9}.${1-9})]>

Properties validated by ValidateTemplate

Validation of properties propNames against glob, regular expression, logic/arithmetic expression, max value (integer), max length (string), min value(integer), min length (string) if validation properties exist. If there are n validation properties, then all n are evaulated. A property can fail on multiple validations.

types
contains the user specified validation key glob pattern to find a space separated list of validation parameters. The typest is built from types and glob
type1 type2 type3 ...
Example: numeric ssn ...
If empty type = propName
types.glob
contains a glob pattern to match against propName defined in the types list.
types.regex
contains a regular expression pattern to match against propName defined in the types list.
types.expr
contains a boolean/arithmetic expression with variable subsititutions to evaluate.
types.maxint
contains the maximum an integer value can have if propName is an integer.
types.minint
contains the minimum an integer value can have if propName is an integer.
types.maxlen
contains the maximum length of a string if propName is a string.
types.minlen
contains the minimum length of a string if propName is a string

Properties set by ValidateTemplate

If validation fails, the error message to be displayed to the user is up to the developer. ValidateTemplate does not store any error messages.
The default for prepend is validate.

prepend.numfailed
contains the number of failed validations.
prepend.failedlist
contains the list of query properties that failed validation along with the type and reason.
Example: propName:type.reason
query.1:numeric.glob
Variable substitutions of the for ${...} are permitted for the attributes.
Version:
ValidateTemplate.java
Author:
Tony Zhao
  • Constructor Details

    • ValidateTemplate

      public ValidateTemplate()
  • Method Details