被Extjs震撼了。想在下一个项目上应用。废话少说,说问题:
关键性代码如下
[code="java"]
var grid = new Ext.grid.GridPanel({
el : "_grid",
ds : ds,
cm : cm,
sm : sm,
iconCls : 'icon-grid',
width : 525,
// height:50,
// autoScroll:true,
autoHeight : true,
frame : true,
title : 'HelloWorld',
autoHeight : true,
// draggable:true,
bbar : pagingBar,
tbar : [{
text : "新增",
handler : function() {
var _window = new Ext.Window({
title : "新增用户",
width : 350,
height : 220,
// frame:true,
items : [{
xtype : "form",
id : "formpanel",
style : "padding:20px,5px,40px,60px",
baseCls : "x-plain",
labelWidth : 40,
items : [{
xtype : "textfield",
name : "username",
id : "username",
fieldLabel : "姓名",
allowBlank : false
}, {
xtype : "textfield",
inputType : "password",
name : "password",
allowBlank : false,
fieldLabel : "密码"
}]
}],
buttons : [{
text : '提交',
handler : function() {
var formpanel1 = _window.findById("formpanel")
if (formpanel1.form.isValid()) {
this.disabled = true;
flag = false;
formpanel1.getForm().submit({
url : 'hworld/hello!Save.action',//提交给后台。后台相应save方法。此处成功调用了该方法
method : 'post',
waitTitle : '请稍等……',
waitMsg : '正在上传数据……', success : function() {
Ext.Msg.alert("成功", "操作成功!");
this.disabled = false;
ds.load({
params : {
start : 0,
limit : 10
}
});
},
failure : function() {
Ext.Msg.alert("出错啦", "数据保存失败!");
this.disabled = false;
}
});
_window.close();
}
}
}, {
text : '重置',
handler : function() {
_window.findById("formpanel").form.reset();
}
}]
});
_window.show();
}
}, "-", {
text : "删除",
iconCls : 'remove',
handler : function() {
var sel = grid.getSelectionModel().getCount();
var ids = "";
if (sel > 0) {
Ext.MessageBox.confirm("请确认", "是否确定删除", function(button,
text) {
if (button == "yes") {
for (var i = 0; i < 20; i++) {
if (grid.getSelectionModel()
.isSelected(i)) {
id = grid.store.getAt(i).get("id");
ids = ids + id + ","
}
}
testdaoimp.delSelected(ids, callbackdel);
function callbackdel(_data) {
if (_data) {
ds.load({
params : {
start : 0,
limit : 10
}
});
Ext.MessageBox
.alert("提示:", "成功删除!");
}
}
}
})
} else {
Ext.MessageBox.alert("提示:", "请选择");
}
}
}],
loadMask : {
msg : "数据加载中,请稍等..."
}
});
[/code]
后台采用struts2来做。
如下:[code="java"]
public class HelloWorld extends ActionSupport {
private String username;
private String password;
TestDao test=new TestDaoImp();
public void Save()
{
Iuser p=new Iuser();
p.setUsername(username);//[color=red]得到formPanel里的username的值,但是显示为null.[/color]
p.setPassword(password);//[color=red]得到formPanel里的password的值,但是显示为null.[/color]
test.savePerson(p);
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}[/code]
请问如何解决?我用了url中带参数肯定是可以,但是不想用这种蠢办法。还是比较推崇struts2的那种自动获取页面数据的办法。