I'm having a problem getting the file object when I use FormPanel, FileUploadField, and Spring.
Here is what I have:
I added the CommonsMultipartResolver bean to my Spring Context file:
Code:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="100000"/>
</bean>
I have a model class with the regular getters and setters:
Code:
pulic class UploadItem{
private String filename;
private CommonsMultipartFile fileData;
....
getters/setters
....
}
My controller class:
Code:
@Controller
@RequestMapping("/Foo")
public class ThingController extends BaseController implements ServlerContextAware{
....
@RequestMapping(value = "/bar", method = RequestMethod.POST)
public @ResponseBody
String createFile(UploadItem item, BindingResults results){
String orgFile = item.getFileData().getOriginalFilename();
return orgFile;
}
I'm using UiBinding to create the form fields, but I'm calling the fileupload field and formpanel to add the other methods in code.
I have a submit button that calls:
And my constructor I take care of the other form requirements:
Code:
form.setMethod(Method.POST);
form.setEncoding(Encoding.MULTIPART);
form.setAction("http://url.com/foo/bar");
form.addSubmitCompleteHandler(new SubmitCompleteHandler(){
@Override
public void onSubmitComplete(SubmitCompleteEvent event){
String results = event.getResults();
Info.display("Upload Response", results);
}
});
When I run the code I get a nullpointerexecption on item.getFileData().getOriginalFilename();
I don't know what the problem is.