Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Struts 2 allows an application to In many places, applications can use use Java 5 annotations as an alternative to XML and Java properties configuration in many places. This page serves as a reference for all annotations across the framework.

...

Action annotations are available when you have Struts 2 scan your the framework scans the classpath for ActionsAction classes, rather than specifying them individually in 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 action Result

Results Annotation

Defines multiple Results

Interceptor Annotations

...

Annotation

Description

After Annotation

Marks a action method that needs to be executed before 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

If you want to To use annotation-based validation, you have to 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, you will directly have type conversion support 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. This means you most likely don't need By using annotations, an application should be able avoid using any ClassName-conversion.properties files.

If you want to To use annotation-based type conversion, you have to annotate the class or interface with the Conversion Annotation.

...