Ext 表单 和 Struct2接受ext表单值的问题

一个疑惑的问题
该问题已经获得圆满解决

用Ext 作的表单以 p.name 这样的方式提交给 struct2的时候 获取不到值
或者 只能通过 request.getParmter("***")获取ext表单里的值吗?

应该如何配置请大家给一点意见
js 代码如下

/********创建FormPanel*******/
ProductFormPanel = Ext.extend(Ext.form.FormPanel,{
	constructor:function(){
		ProductFormPanel.superclass.constructor.call(this,
			{
				labelWidth:60,
				defaultType:'textfield',
				defaults:{anchor:'90%'},
				baseCls:'x-plain',
				items:[
	{fieldLabel:'名称',name:'p.name'},//    ProductEntuty 里的属性 name
	{fieldLabel:'数量',name:'p.num'},//    ProductEntuty 里的属性 num
	{fieldLabel:'类别',
	 hiddenName:'p.type',//    ProductEntuty 里的属性 type   
         xtype:'combo',
						mode:'local',
						displayField:'type',
						readOnly:true,
						triggerAction:'all',
						value:'洗件',
						store:new Ext.data.SimpleStore({
							fields:['type'],
							data:[['洗件'],['固件']]
						})
					},
					{
						fieldLabel:'生产日期',
						xtype:'datefield',
						format:'Y-m-d G:i:s',
						name:'p.date'                               //    ProductEntuty 里的属性 date
					},
					{
						fieldLabel:'是否合格',
						hiddenName:'p.check',		      //    ProductEntuty 里的属性 date
						xtype:'combo',
						model:'local',
						displayField:'check',
						readOnly:true,
						triggerAction:'all',
						value:'合格',
						store:new Ext.data.SimpleStore({
							fields:['check'],
							data:[['合格'],['不合格']]
						})
					}
				]
			})
	},
	submit:function(){
		//表单服务器的提交方法
		this.getForm().submit({
				url:'Productaction_test.action',
				method:'POST',
				success:function(form,action){msg('fb','b');},
				failure:function(form,action){msg('fa','a');}
			});
	},
	reset:function(){
		this.getForm().reset();
	},
	getValue:function(){
		if(this.getForm().isValid()){
			return new Ext.data.Record(this.getForm().getValues());
		}else{
			throw Error('表单未能通过!');
		}
	},
	setValue:function(_r){
		this.getForm().loadRecord(_r);
		
	}
});
/*******创建Windows*********/
ProductWindows = Ext.extend(Ext.Window,{
	form: new ProductFormPanel(),
	constructor:function(){
		this.form = new ProductFormPanel();
		 ProductWindows.superclass.constructor.call(this,
			{
				plain:true,
				width:300,
				modal:true,
				items:this.form,
				closeAction:'hide',
				buttons:[
				{
					text:'确定',
					handler:this.onSubmitClick,
					scope:this
				},
				{
					text:'取消',
					handler:this.onCancelClick,
					scope:this
				}]
			}
		 );
		 this.addEvents('submit');
	},
	close:function(){
		this.form.reset();
		this.hide();
	},
	onCancelClick:function(){
		this.close();
	},
	onSubmitClick:function(){
		try{
			//调用表单提交服务器的方法
			//this.form.submit();
			
			this.fireEvent('submit',this,this.form.getValue());
                        /*问题出在这个地方了 因为Form的AJAX提交是异步执行的所以浏览器在提交的同时 又把this.form.reset() 方法执行了一遍 搞整整28个小时 后来还PeTiRo网友指出了问题的所在 把this.form.reset();去掉就OK了
谢谢 PTR
this.form.reset();*/
//			this.close();
		}catch(_err){
			alert(_err.message);
			return;
		}
	}
});
/*******创建InsertWin*******/
InsertProductWin = Ext.extend(ProductWindows,{
	title:'添加产品'
});
/*******创建UpdateWin*******/
UpdateProductWin = Ext.extend(ProductWindows,{
	load:function(_r){this.form.setValue(_r);},
	title:'修改产品'
});
/*******创建GridPanel*******/
var data = [
	{name:'GH-2323零件',type:'固件',num:18,date:'2009-7-11 00:00:00',check:'合格'},
	{name:'8846零件',type:'洗件',num:20,date:'2009-8-20',check:'不合格'}];
var store = new Ext.data.JsonStore({
//	data:data,
	url:'data/data.jsp',
	autoLoad:true,
	fields:['name','type','num','date','check']
});
var cb = new Ext.grid.CheckboxSelectionModel();
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
cb,
{dataIndex:'name',header:'名称',sortable:true},
{dataIndex:'type',header:'类别',sortable:true},
{dataIndex:'num',header:'数量',sortable:true},
{dataIndex:'date',header:'生产日期',sortable:true},
{dataIndex:'check',header:'是否合格',sortable:true}
]);
ProductGridPanel = Ext.extend(Ext.grid.GridPanel,{
	insertwin:new InsertProductWin(),
	updatewin:new UpdateProductWin(),
	constructor:function(){
		ProductGridPanel.superclass.constructor.call(this,{
			cm:cm,
			region:'center',
			height:500,
			width:'auto',
			store:store,
			border:false,
			stripeRows:true,
			sm:cb,
			title:'测试',
			tbar:[
				{
					text:'添加记录',
					handler:function(){this.insertwin.show();},
					scope:this
				},
				'-',
				{
					text:'修改记录',
					handler:function(){
								try{
									this.updatewin.show();
									this.updatewin.load(this.getSelected());
								}catch(_err){
									msg('系统提示', _err.message);
									this.updatewin.hide();
								}
							},
					scope:this
				},
				'-',
				{
					text:'删除记录',
					handler:function(){
						Ext.MessageBox.confirm('系统提示','您确定要删除所选的信息吗!',this.removePerson,this);
								var a = this.getSelecteds();
								for(var i = 0;i<a.length;i++){
									this.getStore().remove(a[i]);	
								}
							},
					scope:this
				}]
		}),
		this.insertwin.on('submit',this.onInsertWinSubmit,this);
		this.updatewin.on('submit',this.onUpdateWinSubmit,this);
		this.addEvents('rowselect');
	},
	getSelecteds:function(){
		var _sm = this.getSelectionModel();
		return _sm.getSelections();
	},
	getSelected:function(){
			var _sm = this.getSelectionModel();
			var a = _sm.getSelected();
			if(_sm.getCount()==0)
			{
				throw Error('请选择一条记录!');
			}else if(_sm.getCount()>1){
				throw Error('只能选择一条记录!');
			}
			return _sm.getSelected();
	},
	onRowSelect:function(_sel,_index,_r){
			this.fireEvent('rowselect',_r);
	},
	removePerson:function(btn){
			if(btn=='yes'){
				this.remove();
			}
	},
	remove:function(){
		var a = this.getSelecteds();
								for(var i = 0;i<a.length;i++){
									this.getStore().remove(a[i]);	
								}
	},
	insert:function(_r){
		this.getStore().add(_r);
	},
	update:function(_r){
			var st = this.getSelected();
			var data = st.data;
			for(var i in data){
				st.set(i,_r.get(i));
			}
			sr.commit();
	},
	onUpdateWinSubmit:function(_win,_r){
			
			this.update(_r);
	},
	onInsertWinSubmit:function(_win,_r){
var me = this;//这个是大漠帮我搞的 首先感谢大漠穷秋
/*
因为在_win.form.getForm().submit里的执行到success里的function 中调用 this.insert(_r)这里的this
 就是指 _win.form.getForm().submit这个类,所以说这个类里没有insert方法会报错
如果 用me.insert() 的话 就会执行成功
*/
			 _win.form.getForm().submit({  
                url:'Productaction_saveUser.action',
                method:'POST',
                success:function(form,action){
                	msg('fb','b');
                		flag = true;
                		alert(flag);
                		/* 这个写上会说 insert 不是一个function(方法) 为什么呢 
                		this.insert(_r); 
                		*/
			   Ext.MessageBox.confirm('系统提示','添加成功,是否继续!',function(btn){
				if(btn=='no'){
					_win.hide();
				}
			},this);
                },
                failure:function(form,action){msg('fa','a');}
            });  
            
            /*下面这个if为什么不执行了呢  如何能让他执行 */
            if(flag==true){
            	alert('s');
				this.insert(_r);
            }
	}
});


Ext.onReady(function(){
	var grid = new ProductGridPanel();
	var view = new Ext.Viewport({
		renderTo:Ext.getBody(),
		items:[grid]
	});
});


JAVA Struct action 里的代码为
public class ProductAction extends BaseAction {
	public static final String SUCCESS_MANAGER = "success_manager";
	private ProductEntity p;
	
	public ProductEntity getP() {
		return p;
	}
	public void setP(ProductEntity p) {
		this.p = p;
	}

	public String test() throws Exception{
		System.out.println("这一行是可以输出"+getRequest().getParameter("p.type")+"-");
		System.out.println("这一行输出s-"+p.getName()+"-");
		super.outJsonString("{success:true,msg:'成功加载'}");
		return null;
	}}

Struct 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
	<package name="back" extends="struts-default" namespace="/">
		<global-results>
			<result name="done">result.jsp</result>
		</global-results>
		<action name="*action_*" class="com.ysu.action.{1}Action" method="{2}">
			<!-- 有这个配置的话tomcat起动的时候就会报错
			<result type="json">
				<param name="includeProperties">success</param>
			</result>
			 -->
		</action>
	</package>
</struts>

实体类ProductEntity代码如下
public class ProductEntity implements java.io.Serializable{
	private String name;
	private String num;
	private Date date;
	private String type;
	private String check;
	//省略了它的get和set方法	
}

你可能感兴趣的:(tomcat,jsp,Ajax,struts,ext)