JeeWiz Home  
The Model-Driven System Builder
JeeWiz Modeler's Help File for RSA/RSM
 
Contents  >   3.  The Persistence Tier
 


3.4 How to Add Constraints

Constraints can be applied to entity attributes - in the persistence tier - and dataview fields, which are discussed in detail in the next chapter on the service tier.

Constraints limit the valid values on an item of data, over and above its fundamental type. The constraints are checked on entering data (for data-view-fields) or before storing (for attributes).

In RSA you can have up to two constraints on any attribute or field. When data is first entered via a page, it may be validated (see How to validate page data). The screen field (or widget) that is backed by a dataview field will validate against the dataview constraint. If that field is connected to an attribute, it will also validate against the attribute constraint. If the data enters the service layer unvalidated, the dataview will validate against its own constraints and those of any attribute that backs it. Unlike presentation layer checking, only the first failure is reported on a request to store a record. If the data is pushed down to the persistence layer, the entity will validate solely against the attributes constraints. As it is possible to manipulate data at any level through filters, expressions and runtime methods, all these layers of validation are required.

The name and description of the constraint are really there for documentation purposes. There are sensible default messages if the constraint fails but you can override these, using the message field.

There are several constraint types:

  • Maximum and minimum values. These apply to Strings, numbers and Dates
  • Maximum and minimum lengths. These apply to Strings only
  • Expression. A boolean expression written in Java that must evaluate to true.
  • Regular expression. Pattern matching expression.
  • Choices. Must fulfil one of the choices in the list. These are also used for setting dropdown values on fields.

RSA has no simple way to add constraints to attributes as separate units, so two groups of constraint fields have been added to the attribute and dataview field property lists. The Z in front of the property names is just to push them to the bottom of the property window.


Top Tips:
  1. Put time aside to bolt your model down after you have it broadly working.
  2. During boltdown, add constraints first and then security if required.

Links:  

Copyright © 2001-2006 New Technology / enterprise Ltd.