JavaScud | Forum | JIRA | Blog |
  Dashboard > WebWork2文档中文化计划 > WebWork > J2SE 5 Support
  WebWork2文档中文化计划 Log In View a printable version of the current page.  
  J2SE 5 Support
Added by scud, last edited by scud on May 18, 2006  (view change)
Labels: 
(None)

译注

由于Tiger支持还在开发中,所以很多类以及文档可能存在一些错误,所以请慎重使用,并参考源码.

使用WebWork中的J2SE 5 ("Tiger")

工作进行中

这一部分尚未完成! 以后会增加复杂的例子. 现在可以参考xwork-tiger项目目录下的单元测试作为例子.

要用WebWork中的J2SE5支持, 你需要把xwork-tiger.jar添加到classpath下. xwork-tiger.jar文件可以从ivy仓库的lib/tiger目录下获得.

拦截器Annotation

要使用这些Annotation, 需要在你的拦截器栈中加入AnnotationWorkflowInterceptor

Annotation 描述
After Annotation 标记一个需要在result之后执行的action方法.
Before Annotation 标记一个需要在主action方法之前执行的action方法.
BeforeResult Annotation 标记一个需要在result之前执行的action方法.

验证器Annotation

如果需要使用基于annotation的验证, 必须用Validation Annotation标注类或者接口

下面为XWork-tiger项目中的标准验证器Annotation

Annotation 描述
ConversionErrorFieldValidator Annotation 检查是否存在字段类型装换错误.
DateRangeFieldValidator Annotation 检查日期是否在指定范围内.
DoubleRangeFieldValidator Annotation 检查double类型字段是否在指定范围内.
EmailValidator Annotation 检查字段是否为e-mail地址.
ExpressionValidator Annotation 表达式检查.
FieldExpressionValidator Annotation 使用OGNL表达式检查.
IntRangeFieldValidator Annotation 检查数值字段是否在指定范围内.
RegexFieldValidator Annotation 正则表达式检查.
RequiredFieldValidator Annotation 检察字段是否为空.
RequiredStringValidator Annotation 检查String字段是否为空字符串.
StringLengthFieldValidator Annotation 检查String字段长度.
StringRegexValidator Annotation 检查String字段是否符合正则表达式.
UrlValidator Annotation 检查字段是否为合法URL.
Validation Annotation 标记验证为类型级别.
Validations Annotation 用验证annotation组.
VisitorFieldValidator Annotation  
CustomValidator Annotation 自定义验证器的annotation.

类型转换Annotation

如果xwork-tiger.jar文件已经在classpath下, 你可以直接通过泛型来为Map和Collection提供类型转换支持.

简言之, 使用 泛型集合 而不是在Type Conversion文档中指定集合和map的类型. 这就是说基本上不用*ClassName-conversion.properties*文件了.

如果要使用基于annotation的类型转换, 你必须用Conversion Annotation标注类或者接口.

Annotation 描述
Conversion Annotation 在类型级别标注类型转换.
CreateIfNull Annotation 对于Collection和Map类型: 如果空则在Collection和Map里面创建新对象.
Element Annotation 对于泛型类型: 指定Collection和Map中的元素的类型.
Key Annotation 对于泛型类型: 指定Map中的key的类型.
KeyProperty Annotation 对于泛型类型: 指定键属性名字值.
TypeConversion Annotation 类型或者应用程序范围内的类型转换规则.

通过"ant apt"来创建ClassName-conversion.properties

这是一个使用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>
After Annotation (WebWork2文档中文化计划)
AnnotationWorkflowInterceptor (WebWork2文档中文化计划)
Before Annotation (WebWork2文档中文化计划)
BeforeResult Annotation (WebWork2文档中文化计划)
Conversion Annotation (WebWork2文档中文化计划)
ConversionErrorFieldValidator Annotation (WebWork2文档中文化计划)
CreateIfNull Annotation (WebWork2文档中文化计划)
CustomValidator Annotation (WebWork2文档中文化计划)
DateRangeFieldValidator Annotation (WebWork2文档中文化计划)
DoubleRangeFieldValidator Annotation (WebWork2文档中文化计划)
Element Annotation (WebWork2文档中文化计划)
EmailValidator Annotation (WebWork2文档中文化计划)
ExpressionValidator Annotation (WebWork2文档中文化计划)
FieldExpressionValidator Annotation (WebWork2文档中文化计划)
IntRangeFieldValidator Annotation (WebWork2文档中文化计划)
Key Annotation (WebWork2文档中文化计划)
KeyProperty Annotation (WebWork2文档中文化计划)
RegexFieldValidator Annotation (WebWork2文档中文化计划)
RequiredFieldValidator Annotation (WebWork2文档中文化计划)
RequiredStringValidator Annotation (WebWork2文档中文化计划)
StringLengthFieldValidator Annotation (WebWork2文档中文化计划)
StringRegexValidator Annotation (WebWork2文档中文化计划)
TypeConversion Annotation (WebWork2文档中文化计划)
UrlValidator Annotation (WebWork2文档中文化计划)
Validation Annotation (WebWork2文档中文化计划)
Validations Annotation (WebWork2文档中文化计划)
VisitorFieldValidator Annotation (WebWork2文档中文化计划)
Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators