Cross validation is the validation of one value against another value that is entered by the user, or a value that is already somewhere in the Model. An example in our MIAS application could be that the "last scared" date for a kid can never be before the birth date of that kid. This type of validation is often hard to implement, especially because JSF doesn’t offer validators for this. ExtVal offers a set of annotations that lets us define cross validations easily, and in an elegant way. For example, to implement the constraint on the "last scared" date just described, we simply add a single annotation to the lastScared
property:
@Temporal(TemporalType.DATE)
@Column(name = "LAST_SCARED")
@DateIs(type = DateIsType.after, valueOf = "birthDate")
private Date lastScared;
Now it won’t be possible to add a scare date that is before the birth date. The following subsections cover all of the cross validations that are available "out of the box" in ExtVal.