Annotation Reference

Contents

Stripes Annotations

Stripes uses Java 5 metadata to allow your classes to define their behavior in the framework without external information, such as is usually stored in XML files. Placing this information directly into your classes reduces the chance of different files becoming out of sync and reduces the duplication and added complexity required of placing behavioral metadata in many locations.

Dispatch Annotations

The following annotations manage the handling requests and their routing to ActionBean implementations.

@UrlBinding

Applies to

ActionBean Class

Example

@UrlBinding("/action/MyAction")

Class

net.sourceforge.stripes.action.UrlBinding

This annotation can be applied to ActionBean classes to override the generated URL binding for the class with a specific URL. It binds the ActionBean to the specified path so that this bean is invoked in response to that path being requested.

@HandlesEvent

Applies to

ActionBean Method

Example

@HandlesEvent("Save")

Class

net.sourceforge.stripes.action.HandlesEvent

This annotation is applied to handler methods in an ActionBean in order to override the event name which the method responds to (by default the same as the method name). The event name as passed into the request is used to determine which event to execute on the bound ActionBean. When there is no provided event, the default handler will be called should one be defined.

@DefaultHandler

Applies to

ActionBean Method

Example

@DefaultHandler

Class

net.sourceforge.stripes.action.DefaultHandler

When applied to an ActionBean method, this annotion denotes that the method should be executed when there is no event name provided in the request. Note: when only one handler method exists, it is deemed to be the default without need for annotation.

@SessionScope

Applies to

ActionBean Class

Example

@SessionScope

Class

net.sourceforge.stripes.action.SessionScope

Causes the ActionBean, the first time it is used within a user's session, to be placed in the user's HttpSession. On subsequent requests the ActionBean will be retrieved from the HttpSession and re-used.

@Wizard

Applies to

ActionBean Class

Example

@Wizard

Class

net.sourceforge.stripes.action.Wizard

Causes submissions to this ActionBean to be treated as part of a wizard form (a logical form split over more than one physical page). Wizards receive special state management and validation handling.

Parameter

Feature

startEvents

one or more event names that Stripes should treat specially as events initiating a wizrard

Validation Annotations

The following annotations support the validation system of stripes, providing metadata about the expected parameters to a request and their boundary conditions.

@DontValidate

Applies to

ActionBean Method

Example

@DontValidate

Class

net.sourceforge.stripes.action.DontValidate

When applied to an event method, this annotation overrides the stripes validation process, skipping the typical required field and field value checks. ActionBean properties are still converted and bound where possible with the use of this annotation.

@Validate

Applies to

ActionBean Member Variable

Example

@Validate(required=true, minlength=5, maxlength=10)

Class

net.sourceforge.stripes.validation.Validate

This annotation defines the rules of validation for a single field in an ActionBean.

Parameter

Feature

required

(true or false) If true, this field must be present or a validation error will be created

on

If specified, restricts the required-field check to the specified set of events

minlength

(#) The minimum length of the parameter string in characters

maxlength

(#) The maximum number of characters in the parameter string

minvalue

(#) The minimum numeric value for a property (applicable to numeric types only)

maxvalue

(#) The maximum numeric value for a property (applicable to numeric types only)

mask

(regex) A regular expression that must be matched to the parameters string

expression

(EL expression) An expression used to validation non-null values for the field

converter

(class) The converter class that will be used to transform this parameter into its object representation

ignore

(true or false) If true Stripes will ignore this property and not bind any input to it

@ValidateNestedProperties

Applies to

ActionBean Member Variable

Example

@ValidateNestedProperties({
@Validate(field="username", required=true),
@Validate(field="password", required=true)})

Class

net.sourceforge.stripes.validation.ValidateNestedProperties

This annotation can be used for complex object validation. For example, if your ActionBean has a User member variable, with a username property and a password property, you can apply individual field validation to each of the sub fields of the object. This validation may only include @Validate definitions.

@ValidationMethod

Applies to

ActionBean Method

Example

@ValidateMethod

Class

net.sourceforge.stripes.validation.ValidateMethod

Marks a method as containing validation logic to be executed before any handler methods are invoked.

Parameter

Description

priority

(int) Specifies the relative priority of the method when multiple validation methods exist

on

If specified, restricts the validation method's application to the specified set of events

when

Controls whether or not the validation method is executed when validation errors exist

Other Annotations

This section contains assorted other annotations used in Stripes

@Before

Applies to

ActionBean Method

Example

@Before(LifecycleStage.HandlerResolution)

Class

net.sourceforge.stripes.action.Before

Causes a method to be run before the lifecycle stage(s) specified. If no stage(s) are specified, runs before event handler execution.

Parameter

Description

value

(LifecycleStage[]) Specifies one or more lifecycle stages before which to run the method

@After

Applies to

ActionBean Method

Example

@After

Class

net.sourceforge.stripes.action.After

Causes a method to be run after the lifecycle stage(s) specified. If no stage(s) are specified, runs after event handler execution.

Parameter

Description

value

(LifecycleStage[]) Specifies one or more lifecycle stages after which to run the method

@SpringBean

Applies to

ActionBean Method

Example

@SpringBean("/biz/SomeBean")

Class

net.sourceforge.stripes.integration.spring.SpringBean

Used to annotated setter methods as accepting injection of a Spring managed bean. Note that the SpringInterceptor must be configured for this annotation to have any affect.