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

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

Actions Annotation

Group of @Action annotations, maps multiple URLs to the same action

Action Annotation

Defines the URL of an action

InterceptorRefs Annotation

Gropup of @InterceptorRef annotations

InterceptorRef Annotation

Interceptor, or interceptor stack to be applied to at action

Results Annotation

Group of @Result annotations

Result Annotation

Defines a result for an action

Namespace Annotation

Set the path of the action URL (used to overwrite the default)

ResultPath Annotation

Set where the results are located (used to overwrite the default)

ParentPackage Annotation

Set the parent package of the actions (used to overwrite the default)

ExceptionMappings

Group of @ExceptionMapping annotations

ExceptionMapping

Defines an exception mapping

Workflow Annotations

Annotation

Description

InputConfig Annotation

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.

Annotation

Description

After Annotation

Marks a action method that needs to be executed after the result.

Before Annotation

Marks a action method that needs to be executed before the main action method.

BeforeResult Annotation

Marks a action method that needs to be executed before the result.

Validation Annotations

To use annotation-based validation, annotate the class or interface with Validation Annotation.

Annotation

Description

ConversionErrorFieldValidator Annotation

Checks if there are any conversion errors for a field.

DateRangeFieldValidator Annotation

Checks that a date field has a value within a specified range.

DoubleRangeFieldValidator Annotation

Checks that a double field has a value within a specified range.

EmailValidator Annotation

Checks that a field is a valid e-mail address.

ExpressionValidator Annotation

Validates an expression.

FieldExpressionValidator Annotation

Uses an OGNL expression to perform its validator.

IntRangeFieldValidator Annotation

Checks that a numeric field has a value within a specified range.

RegexFieldValidator Annotation

Validates a regular expression for a field.

RequiredFieldValidator Annotation

Checks that a field is non-null.

RequiredStringValidator Annotation

Checks that a String field is not empty.

StringLengthFieldValidator Annotation

Checks that a String field is of the right length.

UrlValidator Annotation

Checks that a field is a valid URL.

Validation Annotation

Marker annotation for validation at Type level.

Validations Annotation

Used to group validation annotations.

VisitorFieldValidator Annotation

Invokes the validation for a property's object type.

CustomValidator Annotation

Use this annotation for your custom validator types.

Resources

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-based type conversion, annotate the class or interface with the Conversion Annotation.

Annotation

Description

Conversion Annotation

Marker annotation for type conversions at Type level.

CreateIfNull Annotation

For Collection and Map types: Create the types within the Collection or Map, if null.

Element Annotation

For Generic types: Specify the element type for Collection types and Map values.

Key Annotation

For Generic types: Specify the key type for Map keys.

KeyProperty Annotation

For Generic types: Specify the key property name value.

TypeConversion Annotation

Used for class and application wide conversion rules.

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.

AnnotationDescription
TilesDefinitionRepresents a <definition> element in tiles.xml
TilesDefinitionsA list of TilesDefinition Annotations

TilesPutAttribute

Represents a <put-attribute> element in tiles.xml
TilesPutListAttributeRepresents a <put-list-attribute> element in tiles.xml
TilesAddAttributeRepresents a <add-attribute> element in tiles.xml
TilesAddListAttributeRepresents a <add-list-attribute> element in tiles.xml

 

Next: Configuration Elements

3 Comments

  1. Are there any plans to add the two missing pages to the Namespace and ParentPackage annotations?

  2. Wouldn't it be wise to split the Result Annotation page into two, one for the Result annotation and one for the Results annotation. All other pages describe one annotation only.

  3. All *Validator annotations describe a type attribute that is required but has a default value. This doesn't to make sense – default values are only meaningful for optional properties. Also, the type attribute is never used in the examples although it's said to be required.

    All examples using *Validator annotations show the annotations out of context. It's always said that they're method-level annotations, so examples should show the annotations being used on some meaningful method.