java.lang.Object
org.apache.wicket.validation.ValidationError
- All Implemented Interfaces:
Serializable
,IClusterable
,IValidationError
A versatile implementation of
IValidationError
that supports message resolution from
IErrorMessageSource
, default message (if none of the keys matched), and variable
substitution.
The final error message is constructed via the following process:
- Try all keys added by calls to
addKey(String)
via the providedIErrorMessageSource
. - If none of the keys yielded a message, use the message set by
setMessage(String)
, if any. - Perform variable substitution on the message, if any.
- Since:
- 1.2.6
- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
-
Constructor Summary
ConstructorDescriptionConstructs an empty errorValidationError
(String message) Constructs a validation error with the specified message.ValidationError
(IValidator<?> validator) Constructs a validation error with the validator's standard key.ValidationError
(IValidator<?> validator, String variation) Constructs a validation error with a variation of validator's standard key. -
Method Summary
Modifier and TypeMethodDescriptionAdds a key to the list of keys that will be tried againstIErrorMessageSource
to locate the error message string.addKey
(IValidator<?> validator) Shortcut for adding a standard message key which is the simple name of the validator' classaddKey
(IValidator<?> validator, String variation) Shortcut for adding a standard message key variation which is the simple name of the validator class followed by a dot and the variationfinal Serializable
getErrorMessage
(IErrorMessageSource messageSource) Retrieves the error message (usually user-facing).getKeys()
Gets error keysfinal String
Gets the default message that will be used when no message could be located via message keys.Retrieves the variables map for this error.void
Sets error keysfinal ValidationError
setMessage
(String message) Sets message that will be used when no message could be located via message keys.setVariable
(String name, Object value) Sets a key and value in the variables map for use in substitution.final ValidationError
setVariables
(Map<String, Object> vars) Sets the variables map for this error.toString()
-
Constructor Details
-
ValidationError
public ValidationError()Constructs an empty error -
ValidationError
Constructs a validation error with the validator's standard key. Equivalent to callingaddKey(IValidator)
- Parameters:
validator
- validator
-
ValidationError
Constructs a validation error with a variation of validator's standard key. Equivalent to callingaddKey(IValidator, String)
- Parameters:
validator
- validatorvariation
- key variation
-
ValidationError
Constructs a validation error with the specified message. Equivalent to callingsetMessage(String)
- Parameters:
message
- message
-
-
Method Details
-
addKey
Adds a key to the list of keys that will be tried againstIErrorMessageSource
to locate the error message string.- Parameters:
key
- a message key to be added- Returns:
- this
ValidationError
for chaining purposes
-
addKey
Shortcut for adding a standard message key which is the simple name of the validator' class- Parameters:
validator
- validator- Returns:
this
-
addKey
Shortcut for adding a standard message key variation which is the simple name of the validator class followed by a dot and the variationIf the variation is empty only the validator's simple class name is used
- Parameters:
validator
- validatorvariation
- key variation- Returns:
this
-
setVariable
Sets a key and value in the variables map for use in substitution.- Parameters:
name
- a variable namevalue
- a variable value- Returns:
- this
ValidationError
for chaining purposes
-
getVariables
Retrieves the variables map for this error. The caller is free to modify the contents.- Returns:
- a
Map
of variables for this error
-
setVariables
Sets the variables map for this error.- Parameters:
vars
- a variables map- Returns:
- this
ValidationError
for chaining purposes
-
getErrorMessage
Description copied from interface:IValidationError
Retrieves the error message (usually user-facing).- Specified by:
getErrorMessage
in interfaceIValidationError
- Parameters:
messageSource
- the message source- Returns:
- the error message
- See Also:
-
getMessage
Gets the default message that will be used when no message could be located via message keys.- Returns:
- message the default message used when all keys yield no message
-
setMessage
Sets message that will be used when no message could be located via message keys.Note: No variable substitution is performed on the given message!
- Parameters:
message
- a default message to be used when all keys yield no message- Returns:
- this
ValidationError
for chaining purposes
-
getKeys
Gets error keys- Returns:
- keys
-
setKeys
Sets error keys- Parameters:
keys
-
-
toString
-