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 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器