2010-12-10 24 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>标签。

相关问题