Struts 2操作类型使用注释转换列表

时间:2012-11-16 20:11:42

标签: java struts2

我正在尝试创建一个自定义类型转换器,以便从String中来回转换对象集合。我的表单中有一个文本区域,并希望在我保存的文本区域中的每个换行符的Collection中创建一个新对象。在显示信息时,我想循环遍历Collection中的对象并将其转换为带有文本区域换行符的String。到目前为止,根据我的注释,我甚至无法启动转换器或接收任何类型的错误。以下是我的班级定义:

@Conversion()
public class FormsEdit extends JWebCrud{

在这个课程中我有一个List:

private List<Formfield> formFields;

在Formnfield类中,我有一个Set:

private Set<Formfieldopts> formfieldoptses = new HashSet<Formfieldopts>(0);

@TypeConversion(converter = "com.webexchange.actions.tpa.setup.forms.FormFieldOptsConverter")
public void setFormfieldoptses(Set<Formfieldopts> formfieldoptses) {
    this.formfieldoptses = formfieldoptses;
}

有人可以指导我如何正确设置这些注释以使转换器启动吗?

Struts 2版本: 2.2.1

Struts拦截器堆栈:

            <interceptor-stack name="stackWithSecurity">
                            <interceptor-ref name="closeHibernateSession" />
            <!--catches exceptions pre or post action class-->
            <interceptor-ref name="exceptionInterceptor" />  
            <interceptor-ref name="security">
                <param name="excludeMethods">executeNoSecurity,executeNoSecurityOrValidation</param>
            </interceptor-ref>
            <interceptor-ref name="alias" />
            <interceptor-ref name="servletConfig" />
            <!-- Puts HTTPResponse and HTTPRequest objects on the action -->
             <interceptor-ref name="openHibernateSession" />
            <!-- Opens a db connection and creates a hibernate session -->
            <interceptor-ref name="prepare" />
            <interceptor-ref name="checkbox" /> <!-- Sets unchecked values into the action with a value of 'false' -->
            <interceptor-ref name="params" /><!-- Sets the parameters from the HTTP request to the action -->
            <interceptor-ref name="staticParams" />
            <interceptor-ref name="conversionError" />
            <!-- adds a field error when the value can't be converted to the right type -->
            <interceptor-ref name="chain">
                <!-- these properties should not be copied from one action to another on a chain -->
                <param name="excludes">dao</param>
            </interceptor-ref>
            <interceptor-ref name="validation">
                <param name="excludeMethods">
                    input,back,cancel,browse,delete,executeNoValidation,executeNoSecurityOrValidation,edit
                </param>
                <param name="validateAnnotatedMethodOnly">true</param>
            </interceptor-ref>
            <interceptor-ref name="workflow">
                <param name="excludeMethods">
                    input,back,cancel,browse,delete,executeNoValidation,executeNoSecurityOrValidation,edit
                </param>
            </interceptor-ref>
        </interceptor-stack>

动作映射:

        <action name="formsSave"
        class="com.webexchange.actions.tpa.setup.forms.FormsEdit"
        method="save">
        <result name="success">/jsp/centers/tpa/setup/forms/EditForms.jsp
        </result>
        <result name="input">/jsp/centers/tpa/setup/forms/EditForms.jsp
        </result>
    </action>

1 个答案:

答案 0 :(得分:0)

感谢Dave的帮助。我的:textarea没有指向我试图转换的收藏品。在我这样做后,转换器开始启动。对我来说完全失败了,对不起。