wood burning stoves*
The moose likes Struts and the fly likes Validation problem during FileUpload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation problem during FileUpload" Watch "Validation problem during FileUpload" New topic
Author

Validation problem during FileUpload

Ajju Chawla
Greenhorn

Joined: Oct 21, 2005
Posts: 21
Hello All,

I've a JSP page in which user enters certain inputs and uploads a file.
These inputs I validate in the validate () method in the Form class. Now the problem is that in case a file of bigger size is uploaded, it takes lot of time to display a message to the user if one of the validation fails.
Is there some way that I validate the inputs from the screen and if everything is ok , then only proceed with file upload??

Thanks
-Aj
Naik Priyanks
Greenhorn

Joined: Nov 15, 2004
Posts: 10
What I would suggest is keep the file input-type disabled in ur jsp when it renders for 1st time or when validation fails.
If validation is successful then redirect to the same jsp with the input type as enabled.
You can do the conf settings in the struts-config.xml.
Ajju Chawla
Greenhorn

Joined: Oct 21, 2005
Posts: 21
Hi, thanks for the reply..

So what u r saying is that during the first submit
1. submit the page without the FileForm fields(disable input-type file).
2. Validate and if there is error than set Action Error.
3. Else redirect on the same page enable input-type = file, and submit on load.

The problem would come in #3. I'll loose the selected files, and it would not be nice to display the same page to the user again...

If I understood u wrong pls tell me.

-Aj
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
If you are using the validator framework you can enable client side validation. I have never used client side validation, so I don't know the details. This uses Javascript and displays a popup message if a validation rule fails. If you are not using the framework or you have complex validation rules, you could implement the same type of validation using custom Javascript.

- Brent
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Validation problem during FileUpload