Interface Constraint
-
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AbstractConstraint
,DateIntervalConstraint
,EnumConstraint
,LengthConstraint
,NotNullConstraint
,NumericIntervalConstraint
,ObjectResolverConstraint
,PatternConstraint
,TypeConstraint
public interface Constraint extends Serializable
A constraint object defines a constraint on a custom type. MethodgetDescription()
allows anyone to dynamically redefine this constraint in another language (for example in javascript to make client-side validation).- Since:
- 7.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Constraint.Description
Represent the description of a constraint.
-
Field Summary
Fields Modifier and Type Field Description static String
MESSAGES_BUNDLE
static Locale
MESSAGES_DEFAULT_LANG
static String
MESSAGES_KEY
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Constraint.Description
getDescription()
Provides a description of a constraint.String
getErrorMessage(Object invalidValue, Locale locale)
Provides an error message to display when some invalid value does not match existing entity.String
getMessageKey()
Provides the message key.boolean
validate(Object object)
Validates the given object against this constraint.
-
-
-
Field Detail
-
MESSAGES_BUNDLE
static final String MESSAGES_BUNDLE
- See Also:
- Constant Field Values
-
MESSAGES_DEFAULT_LANG
static final Locale MESSAGES_DEFAULT_LANG
-
MESSAGES_KEY
static final String MESSAGES_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
validate
boolean validate(Object object)
Validates the given object against this constraint.If some object is null. Constraint should return true while validating unless the constraint deals with nullable state.
- Parameters:
object
- the object to validate- Returns:
- true if the object was successfully validated, false otherwise
-
getErrorMessage
String getErrorMessage(Object invalidValue, Locale locale)
Provides an error message to display when some invalid value does not match existing entity.- Parameters:
invalidValue
- The invalid value that don't match any entity.locale
- The language in which the message should be generated.- Returns:
- A message in the specified language or
- Since:
- 7.1
-
getMessageKey
String getMessageKey()
Provides the message key.- Returns:
- The message key
- Since:
- 11.1
-
getDescription
Constraint.Description getDescription()
Provides a description of a constraint. For example, a constraint which control String format could returnname=PatternMatchingConstraint | parameters= "pattern":"[0-9]+"
- Returns:
- The constraint description.
- Since:
- 7.1
-
-