struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hill" <andrew.david.h...@gridnode.com>
Subject RE: how to dynamically generate several file upload fields
Date Wed, 11 Dec 2002 10:06:23 GMT
I had a similar problem.
At first I tried using a FormFile[] array like one does with other non-file
fields, but it just didnt work, and I dont believe its supported, though it
may be that I was doing something wrong? :-(

I thought of a few other (rather bad) solutions.

The most obvious involves having enough fields defined in your actionForm to
cover all your needs.
ie:
setFile1(FormFile ff)
setFile2 etc....
Then you only render file inputs for the number you actually need at the
time. It sounds like you know at the time you render the page how many you
have which is a big plus, as you thus know how many inputs to include.
This is still not a very satisfactory solution though it may be your best
bet. You will still be limited by the number of fields you have on your
action form, though since its not very practical to upload many files at
once anyway this might not be a problem. If you know the highest number fo
files is say 10, then you only need 10 fields on the form. If its 100 then
100 - but no user is going to want to sit there and browse for that many
files anyway ;-)

Another idea you might try is similar to what I ended up doing. This
involves having a single file input field. The user can only upload one file
at a time, but after each upload they are brought back to the form to add
more. This is implemented by having the form in session scope and the
setFile() method (or whatever you call your file field) adds each FormFile
that is set into it to a list. The advantage of this method is that it
allows for any number of files , but has several disadvantages too - such as
needing to use the session scope, and it feels (very) clunky to the user.

Im still trying to think up a nicer way to do it that covers all my needs.
If you come up with something better do let me know as Id be most interested
:-)

regards
Andrew

-----Original Message-----
From: matthew yee-king [mailto:yeeking@no-future.com]
Sent: Wednesday, December 11, 2002 17:48
To: struts-user@jakarta.apache.org
Subject: how to dynamically generate several file upload fields


Hello

I have a form where the user uploads several files. The number of files
they have to upload is defined in a database, i.e. it can change. How
can I write a form that generates the correct number of file upload
fields automatically and stores the uploaded files into a  FormFile
array in an ActionForm bean?

cheers

matthew

--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message