我在做登陆,formpanel(simple)提交成功,后台STRUTS2传递一个用户的json串:
{success:true,list:{"authority":{"authority":1,"authorityname":"管理 员"},"password":"d68e84140e6956552ce2dd8edc2dd627","userid":38,"username":"911911"}}
json串给了一个中间JSP页面,前台页面的另一个formpanel(simple2)如何获得这个串并自动填充进值?代码如下:
[code="java"]Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
var simple = new Ext.FormPanel({
labelWidth: 75,
frame:true,
hidden:false,
title: '登陆',
bodyStyle:'padding:5px 5px 0',
width: 350,
renderTo:'login',
draggable:true,
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: '用户名',
name: 'username',
maxLength:10,
minLength:6,
allowBlank:false,
maxLengthText:'用户名长度为6至10位',
minLengthText:'用户名长度为6至10位',
blankText:'用户名不能为空'
},{
fieldLabel: '密码',
name: 'password',
inputType:'password',
maxLength:12,
minLength:6,
allowBlank:false,
maxLengthText:'密码长度为6至12位',
minLengthText:'密码长度为6至12位',
blankText:'密码不能为空'
}
],
buttons: [{
text: '登陆',
disabled:false,
handler:function(){submit();}
},{
text: '取消'
}]
});
var _jsonFormReader = new Ext.data.JsonReader({record:"list", successProperty:"@success"}, [{name:"user.userid", mapping:"userid", type:"int"}, {name:"user.username", mapping:"username"}, {name:"user.authorityname", mapping:"authority.authorityname"}]);
var simple2 = new Ext.FormPanel({
labelWidth: 75,
frame:true,
hidden:false,
title: '登陆',
bodyStyle:'padding:5px 5px 0',
width: 350,
reader:_jsonFormReader,
renderTo:'login2',
draggable:true,
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: '用户名',
name: 'user.username',
maxLength:10,
minLength:6,
},{
fieldLabel: '用户ID',
name: 'user.userid',
maxLength:10,
minLength:6,
},{
fieldLabel: '用户权限',
name: 'user.authorityname',
maxLength:10,
minLength:6,
},
]
});
var submit=function(){
if(simple.form.isValid()){
simple.form.submit({
url:'User/login.action',
success:function(form,action){
simple2.form.load({url:"'FormAutoLoad",method:'GET',waitMsg:"waiting"});
},
failure:function(form,action){
Ext.Msg.alert('登录错误','用户名密码错误或用户不存在');
}
});
}
};[/code]