public class ErrorMessageController extends Object implements Serializable
mapConstraintViolation(ConstraintViolation, FormComponent)
and
clearErrorMessagesOnComponent(FormComponent)
should be overridden.
Note: Subclasses of this class must be thread safe.
Modifier and Type | Field and Description |
---|---|
protected Form |
form
A form this controller controls error messages for.
|
Constructor and Description |
---|
ErrorMessageController(Form form)
Creates a new error message controller for the provided form.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addErrorMessage(String message,
FormComponent component)
Adds an error message to a component.
|
void |
clearErrorMessages(FormComponent component)
Clears error messages on the component and all it's descendants.
|
protected void |
clearErrorMessagesOnComponent(FormComponent component)
Clears all error messages on the given component.
|
void |
displayErrorMessages(List<ConstraintViolation> constraintViolations,
FormComponent root)
Displays constraint violations error messages on the form components.
|
protected boolean |
mapConstraintViolation(ConstraintViolation violation,
FormComponent component)
Checks whether the constraint violation error message should be displayed on the component and if yes
then shows the error message on the component.
|
protected final Form form
public ErrorMessageController(Form form)
form
- the form this controller should control error messages for.public void displayErrorMessages(List<ConstraintViolation> constraintViolations, FormComponent root)
Displays constraint violations error messages on the form components. This method tries to map the error messages to the components bound to record properties which are source of the constraint violations.
If subclasses need to override the mapping of a constraint violation to the specific
component they should override the mapConstraintViolation(ConstraintViolation, FormComponent)
method.
constraintViolations
- root
- the component defining the root of the sub-component-tree where to start.mapConstraintViolation(ConstraintViolation, FormComponent)
protected boolean mapConstraintViolation(ConstraintViolation violation, FormComponent component)
Checks whether the constraint violation error message should be displayed on the component and if yes then shows the error message on the component. Subclasses may override this method if checking whether a constraint violation belongs to the component and displaying an error message requires some component specific actions but the following must be true:
forms::FormComponent.excludeConstraintViolation(violation)
returns false
for
this constraint violation and calling forms::FormComponent.includeConstraintViolation(violation)
returns false
.forms::FormComponent.includeConstraintViolation(violation)
returns true
The error message should be added to the component by calling addErrorMessage(String, FormComponent)
.
violation
- the constraint violation to evaluatecomponent
- the component which is a candidate for the error messagetrue
if the error message of the constraint violation has been added to the component;
otherwise false
protected void addErrorMessage(String message, FormComponent component)
message
- the message to addcomponent
- the componentpublic void clearErrorMessages(FormComponent component)
clearErrorMessagesOnComponent(FormComponent)
and peform the custom clearing there.component
- the component which specifies the root of the component
sub-tree to walk throughclearErrorMessagesOnComponent(FormComponent)
protected void clearErrorMessagesOnComponent(FormComponent component)
component
- the component which should be cleared of the error messagesCopyright © 2007-2018 Whitestein Technologies. All Rights Reserved.