使用Spring4和extjs4上传多个文件:控制器获取空的MultipartFile对象列表

问题描述

我有一个使用Spring4和extjs4上传单个文件的工作代码。我正在增强它以允许多个文件上传。 在用户界面上,我可以分隔文件名,保存在商店中并显示文件。 我将表单数据发布到json端点。在控制器上,我看到List对象即将变为空。 有人可以帮我解决这个问题吗?为什么List对象为空?

代码如下所示,位于弹簧控制器侧:

@RequestMapping(value = "upload.json")
    public ModelAndView uploadPaperDocument(@RequestParam(value = "docType",required = false)String documentType,@RequestParam(value = "files",required = false) List<multipartfile> files,Model model,HttpSession httpSession) throws Exception {......}

extjs端的代码是:

var UploadPaperDocumentDialog = function(){

    return {
        init : function(){
        uploadDocumentDialog = new Ext.Window({
            layout: 'fit',width:520,height:300,resizable: false,collapsible: false,modal:true,shadow:true,closable: true,buttonAlign:'center',title: 'Upload',items: {
                xtype:'form',id:'uploadForm',width: 520,bodyPadding: 10,frame: true,timeout:600000,renderTo: Ext.getBody(),items:[
                    {
                        xtype: 'comboBox',name: 'documentType',id: 'docTypeId',fieldLabel: getText('label.document.type'),emptyText: getText('label.select.type'),store: 'docTypestore',displayField: 'key',valueField: 'value',allowBlank : false,selectOnFocus : true,typeAhead: true,forceSelection : true,queryMode:'local',width: 400
                    },{
                        xtype: 'label',text: getText('label.document.attach') + ":",style: "padding-left: 17px;",width: 120,align:'right'
                    },{
                        xtype:'filefield',buttonText: 'browse',msgTarget: 'qtip',name:'files[]',id:'fileId',allowBlank:false,style: "padding-left: 5px;padding-right: 20px",width: 275,listeners: {
                            change: function(fld,value){
                                var files = fld.fileInputEl.dom.files;
                                var names = [];
                                if(files){
                                    names.push({"documentType": Ext.getCmp('docTypeId').getValue(),"fileName": files[0].name});
                                    Ext.data.StoreManager.lookup('uploadDocumentGridStore').loadData(names,true);

                                    console.log(Ext.data.StoreManager.lookup('uploadDocumentGridStore').getCount());
                                }
                                
                            },afterrender:function(cmp){
                               cmp.fileInputEl.set({
                                   multiple:'multiple'
                               });
                            }
                        }
                    },uploadDocumentGrid
                ]                               
            },buttons: [{ 
                text: getText('global.submit'),handler: function(){                                
                    var form = Ext.getCmp('uploadForm').getForm();                                      
                    if(form.isValid()){
                        form.submit({
                           url:'/app/upload.json',scope:this,headers : {
                               'Content-Type' : 'text/html'
                           },success:function(form,action) {
                                var jsonResponse = Ext.decode(action.response.responseText);
                                if(jsonResponse.success == true){
                                    Ext.Msg.alert(getText('global.success.message'),'Document uploaded successfully');
                                    uploadDocumentDialog.close(); 
                                }
                                else{
                                    Ext.Msg.alert(getText('error.occured'),'error.occured');
                                }
                           },failure:function(form,action) {
                               var jsonResponse = Ext.decode(action.response.responseText);
                               if(jsonResponse.success == false){
                                   Ext.Msg.alert(getText('error.occured'),'Error!');
                               }
                               else {
                                   Ext.Msg.alert(getText('error.occured'),'Error occurred while uploading document');
                               }
                               
                            },waitMsg: getText('label.adding')
                        });
                    }
                    else{
                        //throw an error
                        Ext.Msg.alert('Invalid Data','Please enter valid data');
                    }       
                }
            }]
        });
    },showDialog : function(){
        uploadDocumentDialog.show();
    },hideDialog : function(){
        uploadDocumentDialog.close();
    }
    };
}();

function uploadPaperDocumentDialog(){
    UploadPaperDocumentDialog.init();
    UploadPaperDocumentDialog.showDialog();
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...