2010-12-10 6 views
0

Struts 2 ActionSupportクラスに送信する単純なExtJSフォームを実装しています。次のように様々な構成要素のためのコードは次のとおりStruts 2はParamsを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-no-action-mapped-for-namespace-and-action-name-loginact – rahul

答えて

0

送信されたパラメータは、同様の名前のセッタに配置されます。まず、LiveHttpHeaders Firefoxプラグインでフォームパラメータが正しく送信されていることを確認してください。

+0

あなたは正しく、フォームデータが正しく送信されていません。それは何ですか?私は周りを見回してきましたが、その件に関しては何も見つけられませんでした。 – Catie

0

フォームデータが正しくhttpリクエストに渡されていないことがわかったら、私の同僚はフォームデータインターセプタを開発しました。これを使用してデータを手動でロードします。詳細については、<interceptor><interceptor-stack>、および<interceptor-ref>タグを参照してください。

関連する問題