frisk_zhou 2008-11-13 11:22
浏览 204
已采纳

后台无法获取Extjs中formPanel中的数据,请问如何解决。

被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的那种自动获取页面数据的办法。

  • 写回答

2条回答 默认 最新

  • zhang26chao 2008-11-13 12:48
    关注

    提交时不要先关掉窗口,等提交结束并得到服务器端返回的已正确提交的信息后再关闭窗口。
    就是把这句"_window.close(); "放在提交后回调的success里写

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题