@ValueConstraint annotation

back to index

Action

Requires that a value be within a set of boundaries. Unlike the @MinInclusive and similar annotations, this annotation works for just about any data type that can be represented as a string
ValueConstraint can operate on:

Javadoc Ref :  Javadoc reference@ValueConstraint

 Input Types 1
Calendar, Date, Number, CharSequence, byte, int, short, long, double, float
 Output Types
Same as input
   

1Automatic conversion will take place if the provided input does not match any of the input classes, as described in the conversions part of the manual.

Arguments

minInclusive

Minimum acceptable value, inclusive.

maxInclusive
Maximum acceptable value, inclusive.
minExclusive
Minimum acceptable value, exclusive
maxExclusive
Maximum acceptable value, exclusive.
invalidValues
Array of values that the value must NOT be equal to
validValues
Array of values that the value must be equal to
validators
Array of User-defined classes for value validation
message

Literal message to use if validation fails.

errorCode
Error code to use if validation fails.
messageKey
Message key to use if validation fails.

 

Example

@ValueConstraint(minInclusive="B")
private String minInclusiveString;

@ValueConstraint(minExclusive="B")
private String minExclusiveString;

@ValueConstraint(maxInclusive="W")
private String maxInclusiveString;

@ValueConstraint(maxExclusive="W")
private String maxExclusiveString;

@ValueConstraint(validValues={"a","b","c"})
private String validValues;

@ValueConstraint(invalidValues={"a","b","c"})
private String invalidValues;

@ValueConstraint(validators={Sample1.class,Sample2.class})
private String customValidation;

@ValueConstraint(minInclusive="2007-10-01 00:00:00")
private Calendar minInclusiveCalendar;

@ValueConstraint(minExclusive="2007-10-01 00:00:00")
private Calendar minExclusiveCalendar;

@ValueConstraint(maxInclusive="2007-10-01 00:00:00")
private Calendar maxInclusiveCalendar;

@ValueConstraint(maxExclusive="2007-10-01 00:00:00")
private Calendar maxExclusiveCalendar;