|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.smartics.properties.tutorial.property.constraints.ViolationMessagesTutorial
@Document(title="Property Constraints", sortKey="basics0055") @DocCategory(value="basics") public class ViolationMessagesTutorial
This tutorial shows some of the validation messages.
Constructor Summary | |
---|---|
ViolationMessagesTutorial() |
Method Summary | |
---|---|
void |
beanValidationConstraints() The next example shows how violations of constrains defined with Bean Validation are displayed. |
void |
customConstraints() Now we come to custom constraints. |
void |
rangedValueProperty() First let us examine the validation message if we set a property to an invalid value. |
void |
setUp() |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ViolationMessagesTutorial()
Method Detail |
---|
public void setUp()
@DocChapter public void rangedValueProperty()
First let us examine the validation message if we set a property to an invalid value.
The property is declared as follows:
@PropertyIntValueRange(value = { 0, 1, 2, 3, 5, 8, 13, 21, 50, 100 }, defaultValue = 8) @NotNull @PropertyLifecycle(access = AccessType.READ_WRITE) Integer storyPoint();
The property is set to an invalid value:
The resulting message is:
TITLE=Configuration Problem SUMMARY=Configuration ':/::' is invalid. DETAILS=The following 1 violations have been reported: Invalid Property What has happened? Summary: Value '9,999' (Integer) for property 'tutorial.property.constraints.storyPoint' is invalid. The definition is provided by 'inmemory:31456826-29d7-4e5c-a120-a06e847bb4f4'. Details: The violation report: Select one of the following values: 0, 1, 2, 3, 5, 8, 13, 21, 50, 100 What does this implicate for the task having encountered this problem? The system cannot use the property value since it is invalid. What to do now? Please correct the value according to the violation report. The following 1 mandatory properties have not been provided: tutorial.property.constraints.storyPoint No unknown properties have been found. IMPLICATIONS_ON_CURRENT_TASK=The invalid configuration ':/::' cannot be used. WHAT_TO_DO_NOW=Please check your configuration. Remove violations, add mandatory properties and remove unknown properties. Maybe some properties have been misspelled?"
As you can see, the message shows that a validation has been recognized and the detailed validation message for the validation is shown.
You may ask "why is it allowed to set an invalid value?". The reason for this is that we do not validate a value that is set because it may rely on properties that are not yet set or will never be set in the configuration. For instance if you assign a placeholder expression, but the placeholder is not set in the current configuration. If you want your client to immediately check the property, simply fetch it with resolving. Maybe we provide a method that only set a valid property in the future.
@DocChapter public void beanValidationConstraints()
The next example shows how violations of constrains defined with Bean Validation are displayed.
The property is declared as follows:
@PropertyExpression("0") @Min(0) @PropertyLifecycle(access = AccessType.READ_WRITE) int happiness();
The resulting message is:
TITLE=Configuration Problem SUMMARY=Configuration ':/::' is invalid. DETAILS=The following 1 violations have been reported: Invalid Property What has happened? Summary: Value '-1' (Integer) for property 'tutorial.property.constraints.happiness' is invalid. The definition is provided by 'inmemory:6c100657-9187-41e0-b221-732e20c78d01'. Details: The violation report: Min(value=0) What does this implicate for the task having encountered this problem? The system cannot use the property value since it is invalid. What to do now? Please correct the value according to the violation report. No mandatory properties are missing. No unknown properties have been found. IMPLICATIONS_ON_CURRENT_TASK=The invalid configuration ':/::' cannot be used. WHAT_TO_DO_NOW=Please check your configuration. Remove violations, add mandatory properties and remove unknown properties. Maybe some properties have been misspelled?"
@DocChapter public void customConstraints()
Now we come to custom constraints.
The property is declared as follows:
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |