Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Annotations |

Apache Struts 2 Documentation
Annotations
Edit Page Browse Space Add Page Add News
Added by Patrick Lightbody, last edited by Ted Husted on Feb 12, 2007 (view change)

In many places, applications can use 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

Action annotations are available when the framework scans the classpath for Action classes, rather than specifying individual mappings through XML configuration.

Annotation | Description
--- | ---
Namespace Annotation | Overrides the namespace of an action
ParentPackage Annotation | Defines an existing configuration package for the action's package to extend
Result Annotation | Defines an action Result
Results Annotation | Defines multiple Results

## 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.
StringRegexValidator Annotation | Invokes a regular expression to validate a String field.
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.

## 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 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.

## Next: Configuration Elements

Children Show Children Hide Children
ConversionErrorFieldValidator Annotation (Apache Struts 2 Documentation)
VisitorFieldValidator Annotation (Apache Struts 2 Documentation)
DateRangeFieldValidator Annotation (Apache Struts 2 Documentation)
IntRangeFieldValidator Annotation (Apache Struts 2 Documentation)
RequiredStringValidator Annotation (Apache Struts 2 Documentation)
Validations Annotation (Apache Struts 2 Documentation)
BeforeResult Annotation (Apache Struts 2 Documentation)
StringLengthFieldValidator Annotation (Apache Struts 2 Documentation)
Validation Annotation (Apache Struts 2 Documentation)
Element Annotation (Apache Struts 2 Documentation)
FieldExpressionValidator Annotation (Apache Struts 2 Documentation)
CustomValidator Annotation (Apache Struts 2 Documentation)
ExpressionValidator Annotation (Apache Struts 2 Documentation)
CreateIfNull Annotation (Apache Struts 2 Documentation)
Key Annotation (Apache Struts 2 Documentation)
TypeConversion Annotation (Apache Struts 2 Documentation)
EmailValidator Annotation (Apache Struts 2 Documentation)
Before Annotation (Apache Struts 2 Documentation)
StringRegexValidator Annotation (Apache Struts 2 Documentation)
KeyProperty Annotation (Apache Struts 2 Documentation)
RegexFieldValidator Annotation (Apache Struts 2 Documentation)
Conversion Annotation (Apache Struts 2 Documentation)
After Annotation (Apache Struts 2 Documentation)
AnnotationWorkflowInterceptor (Apache Struts 2 Documentation)
UrlValidator Annotation (Apache Struts 2 Documentation)
DoubleRangeFieldValidator Annotation (Apache Struts 2 Documentation)
RequiredFieldValidator Annotation (Apache Struts 2 Documentation)
Result Annotation (Apache Struts 2 Documentation)