gilaras
8 Feb 2012, 1:38 AM
Hi there,
I'm developing an application for managing members of a gun club.
My app currently looks like this:
31474
Right under the picture there's a button to upload an image/picture of the member.
I worked through several tutorials, but i can't get the app to really upload anything ...
Here's my code for the upload form:
Ext.define('MR.view.member.ImageUpload', {
extend: 'Ext.window.Window',
title: 'Bild hochladen',
autoShow: true,
width: 410,
alias: 'widget.imageUpload',
layout: 'anchor',
buttonAlign: 'center',
autoHeight: true,
closable: true,
modal: true,
initComponent: function() {
this.items = [
new Ext.form.FormPanel({
title: 'File Uploader',
width: 400,
bodyPadding: 10,
frame: false,
items: [
{
xtype: 'filefield',
name: 'file',
fieldLabel: 'File',
labelWidth: 50,
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
buttonText: 'Select a file...'
}
],
buttons: [
{
text: 'Upload',
handler: function(){
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
url: '/app/pics/up',
waitMsg: 'Uploading your file...',
success: function(fp, o){
Ext.Msg.alert('Success', 'Your file has been uploaded!');
}
})
}
}
}
]
})
];
this.callParent(arguments);
}
});
After searching on the web for a bit, I found something about an FileUploadBean, that should be created, so I did that too...:
import org.springframework.web.multipart.commons.CommonsMultipartFile;
public class FileUploadBean {
private CommonsMultipartFile file;
public CommonsMultipartFile getFile() {
return file;
}
public void setFile(final CommonsMultipartFile file) {
this.file = file;
}
}
The signature of my controller looks like this:
@RequestMapping(value = "/pics/up", method = RequestMethod.POST)
public void uploadPicture(HttpServletRequest request, FileUploadBean uploadItem, BindingResult result, HttpServletResponse response);
And the problem is the following: everything related to the file is null...(needless to say, an NPE is thrown...)
I don't know what I may be doing wrong, but maybe someone can spot my mistake and tell me how to solve my problem...would be great :D
Thanks in advance and greetz
gilaras~o)
I'm developing an application for managing members of a gun club.
My app currently looks like this:
31474
Right under the picture there's a button to upload an image/picture of the member.
I worked through several tutorials, but i can't get the app to really upload anything ...
Here's my code for the upload form:
Ext.define('MR.view.member.ImageUpload', {
extend: 'Ext.window.Window',
title: 'Bild hochladen',
autoShow: true,
width: 410,
alias: 'widget.imageUpload',
layout: 'anchor',
buttonAlign: 'center',
autoHeight: true,
closable: true,
modal: true,
initComponent: function() {
this.items = [
new Ext.form.FormPanel({
title: 'File Uploader',
width: 400,
bodyPadding: 10,
frame: false,
items: [
{
xtype: 'filefield',
name: 'file',
fieldLabel: 'File',
labelWidth: 50,
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
buttonText: 'Select a file...'
}
],
buttons: [
{
text: 'Upload',
handler: function(){
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
url: '/app/pics/up',
waitMsg: 'Uploading your file...',
success: function(fp, o){
Ext.Msg.alert('Success', 'Your file has been uploaded!');
}
})
}
}
}
]
})
];
this.callParent(arguments);
}
});
After searching on the web for a bit, I found something about an FileUploadBean, that should be created, so I did that too...:
import org.springframework.web.multipart.commons.CommonsMultipartFile;
public class FileUploadBean {
private CommonsMultipartFile file;
public CommonsMultipartFile getFile() {
return file;
}
public void setFile(final CommonsMultipartFile file) {
this.file = file;
}
}
The signature of my controller looks like this:
@RequestMapping(value = "/pics/up", method = RequestMethod.POST)
public void uploadPicture(HttpServletRequest request, FileUploadBean uploadItem, BindingResult result, HttpServletResponse response);
And the problem is the following: everything related to the file is null...(needless to say, an NPE is thrown...)
I don't know what I may be doing wrong, but maybe someone can spot my mistake and tell me how to solve my problem...would be great :D
Thanks in advance and greetz
gilaras~o)