You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 94 Next »

Work in progress

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.

To use J2SE 5 support with the framework, you have to add struts-action-tiger.jar to your classpath.
The struts-action-tiger.jar can be obtained via the Maven repository and is located in the lib/tiger directory.

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 before 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 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

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

 

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

 

CustomValidator Annotation

Use this annotation for your custom validator types.

Type Conversion Annotations

If the xwork-tigerjar is added to the classpath, you will directly have type conversion support for Maps and Collections 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.

If you want to use annotation based type conversion, you have to 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.

Create ClassName-conversion.properties via "ant apt" target

This is an example for the apt ant target:

<target name="apt">
        <mkdir dir="${build}/generated"/>

        <path id="classpath">
            <pathelement path="${basedir}/build/java"/>
            <pathelement path="${basedir}/build/test"/>
            <!-- xwork.jar and xwork-tiger.jar must be in one of the following lib dirs -->
            <fileset dir="${basedir}/lib/build" includes="*.jar"/>
            <fileset dir="${basedir}/lib/default" includes="*.jar"/>
            <fileset dir="${basedir}/lib/spring" includes="*.jar"/>
        </path>

        <property name="pclasspath" refid="classpath"/>

        <!-- Change the includes attribute value to match your annotated java files -->
        <fileset id="sources" dir="." includes="src/test/**/*.java" />

        <pathconvert pathsep=" " property="sourcefiles" refid="sources"/>

        <echo>

            CLASSPATH ${pclasspath}

            SOURCES: ${sourcefiles}

        </echo>

        <exec executable="apt" >
            <arg value="-s"/>
            <arg value="${build}/generated"/>
            <arg value="-classpath"/>
            <arg pathref="classpath"/>
            <arg value="-nocompile"/>
            <arg value="-factory"/>
            <arg value="com.opensymphony.xwork.apt.XWorkProcessorFactory"/>
            <arg line="${sourcefiles}"/>
        </exec>
    </target>
  • No labels