...
In short, instead of specifying the types found in collections and maps as documented in Type Conversion, the collection's generic type is used. This means you most likely don't need any ClassName-conversion.properties files.
Validation Annotations
If you want to use annotatin based validation, you have to annotate the class or interface with Validation Annotation.
These are the standard validator annotations that come with XWork-tiger:
- #ConversionErrorFieldValidator
- #DateRangeFieldValidator
- #EmailValidator
- #ExpressionValidator
- #FieldExpressionValidator
- #IntRangeFieldValidator
- #RegexFieldValidator
- #RequiredFieldValidator
- #RequiredStringValidator
- #StringLengthFieldValidator
- #StringRegexValidator
- #UrlValidator
- #VisitorFieldValidator
NOTE: This is a work in progress and not yet finished!
Anchor | ||||
---|---|---|---|---|
|
RequiredFieldValidator
This validator checks that a field is non-null.
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@RequiredFieldValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
Anchor | ||||
---|---|---|---|---|
|
RequiredStringValidator
This validator checks that a String field is not empty (i.e. non-null with a length > 0).
Parameter | Required | Default | Notes |
---|---|---|---|
trim | no | true | Boolean property. Determines whether the String is trimmed before performing the length check. |
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@RequiredStringValidator(message = "Default message", key = "required.string", shortCircuit = true, trim = true)
|
Anchor | ||||
---|---|---|---|---|
|
StringLengthFieldValidator
This validator checks that a String field is of the right length. It assumes that the field is a String.
Parameter | Required | Default | Notes |
---|---|---|---|
trim | no | true | Boolean property. Determines whether the String is trimmed before performing the length check. |
minLength | no |
| Integer property. The minimum length the String must be. |
maxLength | no |
| Integer property. The maximum length the String can be. |
If neither minLength nor maxLength is set, nothing will be done.
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@StringLengthFieldValidator(message = "Default message", key = "required.field", shortCircuit = true, trim = true, minLength = "5", maxLength = "12")
|
Anchor | ||||
---|---|---|---|---|
|
StringRegexValidator
This validator checks that a String field matches a configure Regular Expression, if it is not an empty String.
Parameter | Required | Default | Notes |
---|---|---|---|
regex | yes | "." | String property. The Regular Expression for which to check a match. |
caseSensitive | no | true | Whether the matching of alpha characters in the expression should be done case-sensitively. |
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@StringRegexValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
Anchor | ||||
---|---|---|---|---|
|
EmailValidator
This validator checks that a field is a valid e-mail address if it contains a non-empty String.
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@EmailValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
Anchor | ||||
---|---|---|---|---|
|
UrlValidator
This validator checks that a field is a valid URL.
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@UrlValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
Anchor | ||||
---|---|---|---|---|
|
IntRangeFieldValidator
This validator checks that a numeric field has a value within a specified range.
Parameter | Required | Default | Notes |
---|---|---|---|
min | no |
| Integer property. The minimum the number must be. |
max | no |
| Integer property. The maximum number can be. |
If neither min nor max is set, nothing will be done.
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@IntRangeFieldValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
Anchor | ||||
---|---|---|---|---|
|
DateRangeFieldValidator
This validator checks that a date field has a value within a specified range.
Parameter | Required | Default | Notes |
---|---|---|---|
min | no |
| Date property. The minimum the date must be. |
max | no |
| Date property. The maximum date can be. |
If neither min nor max is set, nothing will be done.
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@DateRangeFieldValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
Anchor | ||||
---|---|---|---|---|
|
ConversionErrorFieldValidator
This validator checks if there are any conversion errors for a field and applies them if they exist. See Type Conversion Error Handling for details.
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@ConversionErrorFieldValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
Anchor | ||||
---|---|---|---|---|
|
ExpressionValidator
This validator uses an OGNL expression to perform its validation. The error message will be added to the action if the expression returns false when it is evaluated against the value stack.
Parameter | Required | Default | Notes |
---|---|---|---|
expression | yes |
| An OGNL expression that returns a boolean value. |
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@ExpressionValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
Anchor | ||||
---|---|---|---|---|
|
FieldExpressionValidator
This validator uses an OGNL expression to perform its validation. The error message will be added to the field if the expression returns false when it is evaluated against the value stack.
Parameter | Required | Default | Notes |
---|---|---|---|
expression | yes |
| An OGNL expression that returns a boolean value. |
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@FieldExpressionValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
Anchor | ||||
---|---|---|---|---|
|
VisitorFieldValidator
The validator allows you to forward validation to object properties of your action using the objects own validation files. This allows you to use the ModelDriven development pattern and manage your validations for your models in one place, where they belong, next to your model classes. The VisitorFieldValidator can handle either simple Object properties, Collections of Objects, or Arrays.
The error message for the VisitorFieldValidator will be appended in front of validation messages added by the validations for the Object message.
Parameter | Required | Default | Notes |
---|---|---|---|
context | no | action alias | Determines the context to use for validating the Object property. If not defined, the context of the Action validation is propogated to the Object property validation. In the case of Action validation, this context is the Action alias. |
appendPrefix | no | true | Determines whether the field name of this field validator should be prepended to the field name of the visited field to determine the full field name when an error occurs. For example, suppose that the bean being validated has a "name" property. If appendPrefix is true, then the field error will be stored under the field "bean.name". If appendPrefix is false, then the field error will be stored under the field "name". |
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
@VisitorFieldValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
Here we see the context being overridden in the validator mapping, so the action alias context will not be propogated.
ModelDriven example:
Code Block | ||||
---|---|---|---|---|
| ||||
@VisitorFieldValidator(message = "Default message", key = "required.field", shortCircuit = true)
|
This will use the model's validation rules and any errors messages will be applied directly (nothing is prefixed because of the empty message).