In many places, applications can use Java 5 annotations as an alternative to XML and Java properties configuration. This page serves as a reference for all annotations across the framework.
Action Annotations
Note |
---|
Since 2.1, these annotations are provided by the Convention Plugin. Codebehind and Zero Config plugins are deprecated from 2.1 on. |
Action annotations are available when the framework scans the classpath for Action classes, rather than specifying individual mappings through XML configuration. See the Convention Plugin page for information on how to set up classpath scanning to allow the use of Action annotations.
Annotation | Description |
---|---|
Group of @Action annotations, maps multiple URLs to the same action | |
Defines the URL of an action | |
Gropup of @InterceptorRef annotations | |
Interceptor, or interceptor stack to be applied to at action | |
Group of @Result annotations | |
Defines a result for an action | |
Set the path of the action URL (used to overwrite the default) | |
Set where the results are located (used to overwrite the default) | |
Set the parent package of the actions (used to overwrite the default) | |
Group of @ExceptionMapping annotations | |
Defines an exception mapping |
Workflow Annotations
Annotation | Description |
---|---|
Defines what method to execute, or result to be returned if there are validation errors |
Interceptor Annotations
To use these annotations, you have to specify the AnnotationWorkflowInterceptor to your interceptor stack.
Currently only in beta-status, an xwork-tiger project exists that is starting to add some basic J2SE 5 ("Tiger") support to WebWork. Currently, the only Java 5 implementation in xwork-tiger.jar is a Map and Collection support using generics.
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.
Info | ||
---|---|---|
| ||
This is a work in progress and not yet finished! More complex examples will follow. For now, have a look at the unit tests within the xwork-tiger project path. |
...
Annotation | Description |
---|---|
Marks a action method that needs to be executed before after the result. | |
Marks a action method that needs to be executed before the main action method. | |
Marks a action method that needs to be executed before the result. |
Validation Annotations
If you want to To use annotation-based validation, you have to annotate the class or interface with Validation Annotation.
These are the standard validator annotations that come with XWork-tiger:
Annotation | Description | ||
---|---|---|---|
Checks if there are any conversion errors for a field. | |||
Checks that a date field has a value within a specified range. | |||
Checks that a double field has a value within a specified range. | |||
Checks that a field is a valid e-mail address. | |||
Validates an expression. | |||
Uses an OGNL expression to perform its validator. | |||
Checks that a numeric field has a value within a specified range. | |||
Validates a regular expression for a field. | |||
Checks that a field is non-null. | |||
Checks that a String field is not empty. | |||
| |||
| |||
Checks that a String field is of the right length. | |||
Checks that a field is a valid URL. |
| ||
Marker annotation for validation at Type level. | |||
Used to group validation annotations. | |||
Invokes the validation for a property's object type. | |||
Use this annotation for your custom validator types. |
Resources
- Validation using Annotations (arsenalist)
Type Conversion Annotations
By default, type conversion for Maps and Collections using generics is directly supported.
In short, instead of specifying the types found in collections and maps as documented in Type Conversion, the collection's generic type is used. By using annotations, an application should be able to avoid using any ClassName-conversion.properties
files.
To use annotation-If you want to use annotation based type conversion, you have to annotate the class or interface with the Conversion Annotation.
Annotation | Description |
---|---|
Marker annotation for type conversions at Type level. | |
For Collection and Map types: Create the types within the Collection or Map, if null. | |
For Generic types: Specify the element type for Collection types and Map values. | |
For Generic types: Specify the key type for Map keys. | |
For Generic types: Specify the key property name value. | |
Used for class and application wide conversion rules. |
Create ClassName-conversion.properties via "ant apt" target
This is an example for the apt ant target:
...
Tiles Annotations
The Tiles Plugin provides it's own set of Annotations. They can be used to keep tiles.xml
short. Instead tiles definitions can be created by annotating actions.
Annotation | Description |
---|---|
TilesDefinition | Represents a <definition> element in tiles.xml |
TilesDefinitions | A list of TilesDefinition Annotations |
TilesPutAttribute | Represents a <put-attribute> element in tiles.xml |
TilesPutListAttribute | Represents a <put-list-attribute> element in tiles.xml |
TilesAddAttribute | Represents a <add-attribute> element in tiles.xml |
TilesAddListAttribute | Represents a <add-list-attribute> element in tiles.xml |
Next: Configuration Elements
...