Extjs这样写,action如何获得传递过来的参数
var window_add_duty = new Ext.Window({ title : '添加职务', width : 340, height : 250, closeAction : 'hide', autoHeight : true, modal : true, resizable : false, bodyStyle : 'padding:5px 5px 0 0', items : [new Ext.form.FormPanel({ url : 'duty/addDuty.action', defaultType : 'textfield', layout : 'form', defaults : { widht : 233, msgTarget : 'side' }, border : false, baseCls : 'x-plain', anchor : '100%', labelWidth : 60, labelAlign : 'right', items : [{ fieldLabel : '职务名称', id : 'duty_name', name : 'duty_name', allowBlank : false, maxLength : 20, width : '233' }, { fieldLabel : '备注', xtype : 'textarea', name : 'duty_remark', maxLenght : 100, width : 233 }], buttonAlign : 'right', minButtonWidth : 60, buttons : [{ text : '添加', handler : function(btn) { var frm = this.ownerCt.form; if (frm.isValid()) { btn.disable(); var cnfield = frm.findField('duty_name'); frm.submit({ waitTitle : '请稍后...', waitMsg : '正在提交表单数据,请稍后...', success : function(form, action) { var store = grid_duty.getStore(); var duty = new Duty({ dutyId : action.result.dutyId, dutyName : cnfield.getValue(), remark : form.findField('duty_remark') .getValue() }); store.insert(0, [duty]); window_add_duty.setTitle('[' + frm.getValue() + ']添加成功!!'); cnfield.reset(); btn.enable(); }, failure : function() { Ext.Msg.show({ title : ' 错误提示', msg : '"' + cnfield.getValue() + '"' + '已经存在', buttons : Ext.Msg.OK, fn : function() { cnfield.focus(true); btn.enable(); }, icon : Ext.Msg.ERROR }); } }); } } }, { text : '重置', handler : function() { this.ownerCt.form.reset(); } }, { text : '取消', handler : function() { this.ownerCt.ownerCt.hide(); } }] })] });
重点是这句,这是把ext封装的html的form给提交了,这样在后台跟取得一个html form的方法就一样了
[解决办法]
用struts2,接收提交的数据,看你的form的参数名:
duty_name duty_remark
在你的Action中要有相关的set方法。
以上是最麻烦的方法。
简单:你的action定义一duty类
Duty : dutyName,dutyRemark,有set、get方法
在你的action中定义Duty对象duty,也要有set、get方法,
而在你的formPanel中定义的name则为
duty.dutyName
duty.dutyRemark
这样,action中就直接对号入座了。
这部分,建议看下struts2的例子即可,是struts2的入门级东东了 哈
另外在你的action中,不建议出现request、response