2010-12-10 46 views
0

我正在實現一個提交給Struts 2 ActionSupport類的簡單ExtJS表單。對於各種組件的代碼如下:Struts 2不會將ExtJS表單中的參數傳遞給ActionSupport類

MyAction.java:

//packaging and imports 
public class MyAction extends ActionSupport { 
    private String aField; 
    private String anotherField; 

    public String execute() throws Exception { 
     System.out.println(afield + " " + anotherField); //just checking values, atm 
     return ActionSupport.SUCCESS; 
    } 

    public String getAField() { 
     return this.aField; 
    } 

    public void setAField(String aField) { 
     this.aField = aField; 
    } 

    public String getAnotherField() { 
     return this.anotherField; 
    } 

    public void setAnotherField(String anotherField) { 
     this.anotherField = anotherField; 
    } 
} 

myForm.js:

Ext.onReady(function() { 
    Ext.QuickTips.init(); 

    // turn on validation errors beside the field globally 
    Ext.form.Field.prototype.msgTarget = 'side'; 

    var myForm = new Ext.form.FormPanel({ 
     id: 'myFormId', 
     url: 'submitMyForm.action', 
     defaults: { 
      xtype: 'textfield' 
     }, 
     items: [ 
      { 
       fieldLabel: 'A Field', 
       id: 'aField', 
       name: 'aField', 
       allowBlank: false 
      }, 
      { 
       fieldLabel: 'Another Field', 
       id: 'anotherField', 
       name: 'anotherField', 
       allowBlank: false 
      } 
     ], 
     renderTo: 'contentMain' 
    }); 

    var submitButton = new Ext.Button({ 
     text: 'SUBMIT', 
     handler: function(button, event) { 
      myForm.getForm().submit({ 
       url: 'submitMyForm.action', 
       failure: function() { 
        Ext.Msg.alert('Error', 'Can not save data.'); 
       } 
      }); 
     } 
    }); 
}); 

struts.xml中:

<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
    "http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
    <package name="myPackage" namespace="/" extends="json-default"> 
     <action name="submitMyForm" class="mycodepackage.MyAction"> 
      <result name="*" type="json"> 
       <param name="includeProperties">aField</param> 
      </result> 
     </action> 
    </package> 
</struts> 

當提交按鈕被按下,我的動作正常執行,並且除標準調試數據打印外:

null null 

JSON結果正確地發回,但當然也爲空:

14:22:17,046DEBUG JSONResult:68 - Adding include property expression: aField 
14:22:17,052DEBUG JSONWriter:68 - Ignoring property because of include rule: anotherField 
14:22:17,053DEBUG JSONUtil:68 - [JSON]{"aField":null} 

現在,這是我的理解是,在表單中輸入的值應插入的實例變量我行動課。我錯了嗎?如果沒有,會出現什麼問題?如果是這樣,我能做些什麼來確保表單數據被髮送到我的操作處理程序?

謝謝。

+0

請你幫我出這一點:[錯誤上運行的應用「無動作映射爲命名空間/和動作名稱登錄] [1] [1]:http://stackoverflow.com/questions/6966890/getting-error-there-is-no-action-mapped-for-namespace-and-action-name-loginact – rahul 2011-08-07 04:15:17

回答

0

發送的任何參數都將被放入類似命名的setters中。爲什麼不首先檢查表單參數是否使用LiveHttpHeaders Firefox插件正確發送。

+0

你說得對,表單數據沒有被正確發送任何想法可能是什麼原因我一直在四處尋找,並沒有找到任何關於這個問題的任何想法,不勝感激。 – Catie 2010-12-13 16:49:50

0

一旦我們意識到表單數據沒有正確傳遞到http請求中,我的同事開發了一個表單數據攔截器,我們用它來手動加載數據。有關更多信息,請查看<interceptor><interceptor-stack><interceptor-ref>標籤。

相關問題