ext form的组件用法,以及提交返回数据的注意事项

extjs中form的用法,效果图:


上代码:

var form =new Ext.FormPanel({
	url : 'xxx.do',
	renderTo :document.body,
	frame : true,
	title : '表单',
	width : 500,
	x:300,
	items : [
		{
			xtype : 'textfield',//相当于html中<input type="text" />
			fieldLabel : '姓名',
			name : 'username',
			allowBlank : false,
			value : '',
			readonly : 'readonly'
		},
		{
			fieldLabel : '密码',//相当于html中<input type="password" />
			name : 'password',
			xtype : 'textfield',
			inputType : 'password',
			allowBlank : false
		},
		{//时间插件
			fieldLabel : '时间',
			name : 'released',
			xtype : 'datefield',
			format:'Y-m-d'
			//disabledDays: [0,6]
		},
		{//radio
			xtype:'fieldset',
			title:'颜色',
			autoHeight:true,	
			defaultType:'radio',
			hideLabels: true,
			items: [
					{ boxLabel: '彩色', name: 'color', inputValue: '1', checked: true},
					{ boxLabel: '白色', name: 'color', inputValue: '2' },
					{ boxLabel: '黑色', name: 'color', inputValue: '3' }
				]
		},
		{//checkbox
			title:'食物',
			xtype:'fieldset',
			autoHeight:true,
			items: [
					{ boxLabel: '馒头', name: 'food', inputValue: '1',xtype:'checkbox', checked: true},
					{ boxLabel: '面包', name: 'food', inputValue: '2' ,xtype:'checkbox'},
					{ boxLabel: '米饭', name: 'food', inputValue: '3' ,xtype:'checkbox'}
				]
		},
		{
			xtype : 'htmleditor',
			name : 'description',
			anchor: '100%'
		}
		],
	buttons : [
		{
			text : '确定',
			handler:function(){
			//var pass=form.getForm().findField('sex');
			//alert( pass.getValue());
			//alert( pass.getGroupValue ( ));
			form.form.submit({
				success:function(form,action){
					alert('succ'+action.response.responseText);//responseText后台返回的全部数据
				},
				failure:function(form,action){
					alert('error'+action.response.responseText);
				}
			});
			}
		},
		{
			text : '取消',
			handler:function(){
				alert('取消');
			}
		}
		]
}); 


 后台servlet处理提交上来的数据,获取的时候跟正常的html的获取方式是一样的,代码: 

		String username=request.getParameter("username");
		String password=request.getParameter("password");
		String released=request.getParameter("released");
		String color=request.getParameter("color");
		String[] food=request.getParameterValues("food");//取多选框的值
		String description=request.getParameter("description");

后台返回的时候一定要注意,返回的是json格式的字符串,而且一定要有success:true,不然前台的ext定义的回调函数就会走failure的方法,正确的代码如下:

PrintWriter out=response.getWriter();
result="{success:true , msg:'form',xxxx:'xxxxx'}";
out.write(result);
out.close();


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值