5

我正在尝试创建一个自定义类型转换器来从字符串来回转换对象集合。我的表单中有一个文本区域,并且想在集合中为我保存的文本区域中的每个换行符创建一个新对象。显示信息时,我想遍历集合中的对象并将其转换为带有换行符的字符串,用于我的文本区域。到目前为止,我什至无法让我的转换器触发或接收基于我拥有的注释的任何类型的错误。下面是我的类定义:

@Conversion()
public class FormsEdit extends JWebCrud{

在这个类里面我有一个列表:

private List<Formfield> formFields;

在 Formnfield 类中,我有一个集合:

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

1 回答 1

0

感谢戴夫的帮助。我的 s:textarea 没有指向我试图转换的集合。在我这样做之后,转换器开始点火。对不起,我完全失败了。

于 2012-11-19T15:47:50.980 回答