一种是form里面直接提交传值给后台的例子:
Ext.onReady(function(){
var formPanel = new Ext.FormPanel({
id : "formPanel",
name : "formPanel",
width : 800,
renderTo : "formPanelDiv",
onSubmit: Ext.emptyFn,
submit: function(){
this.getEl().dom.action="formPanel.htm";
this.getEl().dom.submit();
},
items : [
new Ext.form.TextField({
id : "id",
name : "id",
allowBlank : false,
blankText : "ID不能为空",
fieldLabel : "ID",
labelStyle : "text-align:right"
}),
new Ext.form.TextField({
id : "name",
name : "name",
allowBlank : false,
blankText : "姓名不能为空",
fieldLabel : "姓名",
labelStyle : "text-align:right"
}),
new Ext.form.RadioGroup({
fieldLabel : "性别",
labelStyle : "text-align:right",
width : 80,
items : [
new Ext.form.Radio({
name : "sex",
boxLabel : "男",
inputValue : "male",
width : 20
}),
new Ext.form.Radio({
name : "sex",
boxLabel : "女",
inputValue : "female",
width : 20
})
]
}),
new Ext.form.TextField({
id : "email",
name : "email",
fieldLabel : "邮箱",
labelStyle : "text-align:right"
})
],
buttons : [
{
text : "登录",
id : "btn_login",
handler : function(){
if(formPanel.getForm().isValid()){
formPanel.getForm().submit();
}
}
},
{
text : "重置",
id : "btn_reset",
handler : function(){
formPanel.getForm().reset();
}
}
],
buttonAlign : "center"
});
});
后台是controller或jsp可以直接接收form提交过来的值
String sex= request.getParameter("sex");
...........
第二种是用ajax传值的例子:
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.override(Ext.form.RadioGroup, {
getValue: function(){
var v;
if (this.rendered) {
this.items.each(function(item){
if (!item.getValue())
return true;
v = item.getRawValue();
return false;
});
}
else {
for (var k in this.items) {
if (this.items[k].checked) {
v = this.items[k].inputValue;
break;
}
}
}
return v;
},
setValue: function(v){
if (this.rendered)
this.items.each(function(item){
item.setValue(item.getRawValue() == v);
});
else {
for (var k in this.items) {
this.items[k].checked = this.items[k].inputValue == v;
}
}
}
});
var radiogroup= new Ext.form.RadioGroup({
fieldLabel : "radioGroup",
items : [{
boxLabel : '男',
inputValue : "男",
name : "rg",
checked : true
}, {
boxLabel : '女',
name : "rg",
inputValue : "女"
}]
});
var _form=new Ext.form.FormPanel({
renderTo:'login-form',
title:'系统登录',
frame:true,
width:290,
height:160,
layout:'form',
buttonAlign:'center',
labelAlign:'center',
defaults:{width:160,labelWidth:80,xtype:'textfield'},
items:[
{fieldLabel:'用 户 名',vtype:'alpha',id:'name',name:'name'},
{fieldLabel:'通 行 证',inputType:'password',vtype:'alpha',id:'pass',name:'pass'},
radiogroup
],
buttons:[
{
text:'登 录',
style:'margin-right:15',
handler : function(){
if(_form.getForm().isValid()){
Ext.Ajax.request({
method : "post",
url : "test2.jsp",
params : {
sex : radiogroup.getValue()
},
callback : function(options,success,response){
Ext.Msg.alert('提示',response.responseText);
}
});
}
}
},
{
text:'清 除',
style:'margin-left:15',
handler:function(){
var _name=_form.findById('name').setValue('');
var _pass=_form.findById('pass').setValue('');
}
}
]
});
});
在后台的controller或jsp,可以直接用
String sex = request.getParameter("sex");
接收传值。
不知道大家有没发现,有ajax与没有ajax,传值是有点区别的