|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ValidationMessage
Describes validation messages as used by the JGoodies Validation framework.
All validation messages provide a formatted text (formattedText()
)
and are categorized into types of different severity (@link #severity()}).
Validation messages are collected during the validation process and
are held by instances of ValidationResult
.
This class has been designed to be decoupled from user interface components
(views) that present and edit the validated data. The design goal is to be
able to use the same validation mechanism on the server side, in the domain
layer, in a view-less model layer, and in the presentation layer.
And we want to ensure that multiple views can present the same model,
and so we typically don't store a view in the validation message.
On the other hand we want to detect which validation messages belongs
to a given user interface component, for example to let the component
paint a warning indication.
This association between message and view is established by the message key
that can be shared between messages, validators, views, and other parties.
It can be requested using the key()
method. The association is
checked using #equals
; implementors that use rich objects
as keys may consider overriding #equals
.
For example, a validator validates an address object and reports
that the zip code is invalid. You may choose the association key
as "address.zipCode"
. All views that present the zip code
can now check and verify whether a validation result contains messages
with this key and may paint a special warning background.
If the validated data contains two different address objects, let's say
a shipping address and a physical address, the address validator may
add a prefix and create keys like physical.address.zipCode
and shipping.address.zipCode
. A view can now differentiate
between the two zip codes.
We've choosen to let the ValidationMessage
check whether
an association key matches or not. This way, an implementation of this
interface can choose to provide special checks. The default behavior
in class AbstractValidationMessage
just checks whether a given association key equals a stored key.
Implementors may hold additional objects, for example the validation target,
a description of the target, or a description of the validated property.
Implementors are encouraged to implement #equals
and
#hashCode
to prevent unnecessary change notifications
for the result property when a ValidationResultModel
gets a new ValidationResult. See for example the implementation of method
PropertyValidationMessage.equals(Object)
.
ValidationResult
,
AbstractValidationMessage
Method Summary | |
---|---|
String |
formattedText()
Returns a formatted text that describes the validation issue this message represents. |
Object |
key()
Returns this message's association key that can be used to model a loose coupling between validation messages and views that present the validated data. |
Severity |
severity()
Returns this message's severity: error or warning. |
Method Detail |
---|
Severity severity()
Severity.OK
is not allowed as the severity
of a single message, but OK is a valid ValidationResult severity.
String formattedText()
Object key()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |