Extjs的form传递参数问题。
本帖最后由 showbo 于 2012-08-10 10:49:19 编辑 addEmployee.jsp中的form表单代码
Ext.onReady(function() {
var form = new Ext.form.FormPanel({
baseCls: 'x-plain',
labelWidth: 55,
url:'save-form.php',
defaultType: 'textfield',
items: [{
fieldLabel: '用户名',
name: 'username',
anchor:'100%' // anchor width by percentage
},{
fieldLabel: '密码',
inputType: 'password',
name: 'password',
anchor: '100%' // anchor width by percentage
},{
xtype: 'radiogroup',
fieldLabel: '性别',
name:'gender',
items: [
{boxLabel: '男', name: 'rb-auto', inputValue: 1},
{boxLabel: '女', name: 'rb-auto', inputValue: 2},
]
}],
buttons: [{
text: '保存',
handler: function(){
Ext.Ajax.request({
url : 'manage_add.action',
params:{'username':'username','password':'password','gender':'gender'},
method : 'post',
success : function(response) {
Ext.Msg.alert("提示", "方法调用成功");
},
failure : function() {
Ext.Msg.alert("提示", "方法调用失败");
}
});
}
},{
text: '重置',
handler: function(){
form.form.reset();
}
}]
});
package cn.feng.action;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionContext;
import cn.feng.bean.Employee;
import cn.feng.service.EmployeeService;
@Controller @Scope("prototype")
public class EmployeeManageAction {
@Resource EmployeeService employeeService;
private Employee employee;
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public String addUI(){
return "add";
}
public String add(){
employeeService.save(employee);
ActionContext.getContext().put("message", "保存成功");
return "message";
}
}
Ext.Ajax.request({
url : 'manage_add.action',
params:form.getForm().getValues() ,//获取表单输入的键值对
method : 'post',
success : function(response) {
Ext.Msg.alert("提示", "方法调用成功");
},
failure : function() {
Ext.Msg.alert("提示", "方法调用失败");
}
});
items: [{
fieldLabel: '用户名',
id: 'username',
name: 'username',
anchor:'100%' // anchor width by percentage
},
......
buttons: [{
text: '保存',
handler: function(){
Ext.Ajax.request({
url : 'manage_add.action',
params:{
'username': Ext.get('username').dom.value,//注意这样调用参数
......... //这里不一一列举了
},
method : 'post',
success : function(response) {
Ext.Msg.alert("提示", "方法调用成功");
},
failure : function() {
Ext.Msg.alert("提示", "方法调用失败");
}
});
}
},