getOriginalFilename() in validate()
Hi,
I'm a Spring Newbie and my first task is to upload a file from a web form, validate the values in the file and then put these data into a database. So, the most things are working already, but I have a problem with resolving the filename in my validation class.
I know there is the possibility to resolve the filename in the Controller like this:
FileUploadController:
Code:
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
throws ServletException, IOException {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
CommonsMultipartFile fileinp = (CommonsMultipartFile) multipartRequest.getFile("file");
String filename = fileinp.getOriginalFilename();
[...]
but i need the filename in my Validator and the Validator is called before the Controller gets in action.
[...]-servlet.xml:
Code:
<bean id="fileUploadController" class="[...].FileUploadController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>fileUploadBean</value></property>
<property name="commandClass"><value>[...].FileUploadBean</value></property>
<property name="formView"><value>upload</value></property>
<property name="validator">
<ref bean="queryValidator"/>
</property>
<property name="queryManager">
<ref bean="queryMan"/>
</property>
</bean>
QueryValidator.java:
Code:
public void validate(Object obj, Errors errors) {
// no request... -> no getOriginalFilename() ???
[...]
Thanks for any help,
4had