2012-11-16 36 views
5

我正在嘗試創建一個自定義類型轉換器,以便將對象集合從一個字符串中來回轉換。我的表單中有一個文本區域,並且希望在保存的文本區域中爲每個換行符在集合中創建一個新對象。在顯示信息時,我想遍歷集合中的對象,並將其轉換爲帶有換行符的字符串以顯示我的文本區域。到目前爲止,我甚至無法根據我所擁有的註釋讓我的轉換器觸發或接收任何類型的錯誤。下面是我的類定義:Struts 2操作類型使用註釋轉換列表

@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; 
} 

是否有人可以直接我如何正確設置這些註釋以使Converter能夠觸發?

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

S2版本?動作/攔截器堆棧配置?有關掃描或轉換過程的任何關於DEBUG/devMode日誌級別的信息? –

+0

S2版本:2.2.1 –

+0

我在devMode中擁有Struts 2配置。我也爲根記錄器開啓了DEBUG。但是,我沒有看到Struts輸出任何東西。 –

回答

0

戴夫感謝您的幫助。我的s:textarea沒有指向我正在嘗試轉換的集合。我這樣做後,轉換器開始起火。對我來說,總是失敗,對不起。