You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by matthew yee-king <ye...@no-future.com> on 2002/12/11 10:47:43 UTC

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: how to dynamically generate several file upload fields

Posted by Gemes Tibor <ge...@regens.hu>.
2002. december 11. 11:10 dátummal matthew yee-king ezt írtad:
> that sounds like the best solution to me for the moment. I need a quick
> solution as ever ;)
>
> > 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:-)

I think that the file input field can accept multiple files for upload.

Hth,

Tib

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: how to dynamically generate several file upload fields

Posted by Andrew Hill <an...@gridnode.com>.
Wow. That was quick. I spent ages when I did it.
Good work :-)

-----Original Message-----
From: matthew yee-king [mailto:yeeking@no-future.com]
Sent: Wednesday, December 11, 2002 19:43
To: Struts Users Mailing List
Subject: Re: how to dynamically generate several file upload fields


I've got this working nicely now. And its not a /total/ HCI disaster by
any means :).

cheers

- matthew


On Wed, 11 Dec 2002 10:10:17 +0000
matthew yee-king <ye...@no-future.com> wrote:

>
> > 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.
> >
>
> that sounds like the best solution to me for the moment. I need a
> quick solution as ever ;)
>

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: how to dynamically generate several file upload fields

Posted by matthew yee-king <ye...@no-future.com>.
I've got this working nicely now. And its not a /total/ HCI disaster by
any means :). 

cheers

- matthew


On Wed, 11 Dec 2002 10:10:17 +0000
matthew yee-king <ye...@no-future.com> wrote:

> 
> > 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.
> > 
> 
> that sounds like the best solution to me for the moment. I need a
> quick solution as ever ;)
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: how to dynamically generate several file upload fields

Posted by Andrew Hill <an...@gridnode.com>.
Aha. here we go. Its a known limitation to be resolved "later".
Heres the link to bugzilla:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6847

-----Original Message-----
From: Andrew Hill [mailto:andrew.david.hill@gridnode.com]
Sent: Wednesday, December 11, 2002 18:39
To: Struts Users Mailing List
Subject: RE: how to dynamically generate several file upload fields


Yeh. I rememeber reading in the html specs (or was that the 'draft' for file
uplaoding with html) that it would support multiple files, alas the browsers
dont. One can of course have multiple <input type="file" elements, but I
dont think this can be mapped to the same property in the actionForm as an
array of FormFile. I never got it to work , and I vaguely remember someone
saying something to that effect a while ago on the list. Doing a quick web
search now to see if can get more info.

-----Original Message-----
From: Gemes Tibor [mailto:gemes@regens.hu]
Sent: Wednesday, December 11, 2002 18:27
To: Struts Users Mailing List
Subject: Re: how to dynamically generate several file upload fields


2002. december 11. 11:21 dátummal Andrew Hill ezt írtad:
> I think to get multiple files working (ie: array of FormFile) would need
> changes to the classes in the struts upload package. I would imagine that
> it is not simple (mainly on the evidence that nobodys done it yet!).

Oh, I haven't think of this. Yes, <input type="file"> can accept files (at
least the html specs is talking about "entering files" etc) , but it might
not be handled by the upload package. :(

Tib

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: how to dynamically generate several file upload fields

Posted by Andrew Hill <an...@gridnode.com>.
Yeh. I rememeber reading in the html specs (or was that the 'draft' for file
uplaoding with html) that it would support multiple files, alas the browsers
dont. One can of course have multiple <input type="file" elements, but I
dont think this can be mapped to the same property in the actionForm as an
array of FormFile. I never got it to work , and I vaguely remember someone
saying something to that effect a while ago on the list. Doing a quick web
search now to see if can get more info.

-----Original Message-----
From: Gemes Tibor [mailto:gemes@regens.hu]
Sent: Wednesday, December 11, 2002 18:27
To: Struts Users Mailing List
Subject: Re: how to dynamically generate several file upload fields


2002. december 11. 11:21 dátummal Andrew Hill ezt írtad:
> I think to get multiple files working (ie: array of FormFile) would need
> changes to the classes in the struts upload package. I would imagine that
> it is not simple (mainly on the evidence that nobodys done it yet!).

Oh, I haven't think of this. Yes, <input type="file"> can accept files (at
least the html specs is talking about "entering files" etc) , but it might
not be handled by the upload package. :(

Tib

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: how to dynamically generate several file upload fields

Posted by Gemes Tibor <ge...@regens.hu>.
2002. december 11. 11:21 dátummal Andrew Hill ezt írtad:
> I think to get multiple files working (ie: array of FormFile) would need
> changes to the classes in the struts upload package. I would imagine that
> it is not simple (mainly on the evidence that nobodys done it yet!).

Oh, I haven't think of this. Yes, <input type="file"> can accept files (at 
least the html specs is talking about "entering files" etc) , but it might 
not be handled by the upload package. :(

Tib

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: how to dynamically generate several file upload fields

Posted by Andrew Hill <an...@gridnode.com>.
Well you can do it for text fields already - just pump out several fields
with the same name. Works for almost all field types actually.

...just not files :-(

I think to get multiple files working (ie: array of FormFile) would need
changes to the classes in the struts upload package. I would imagine that it
is not simple (mainly on the evidence that nobodys done it yet!).


-----Original Message-----
From: matthew yee-king [mailto:yeeking@no-future.com]
Sent: Wednesday, December 11, 2002 18:10
To: Struts Users Mailing List
Subject: Re: how to dynamically generate several file upload fields



> 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.
>

that sounds like the best solution to me for the moment. I need a quick
solution as ever ;)

> 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:-)
>


I'm thinking the best way would be to get into the taglibs and write
some new html: tags that let you generate sets of text fields or file
fields that are stored to an ActionForm's arrays in the same way you can
with the<html:select multiple="yes"..> tags.

thanks for the tips

matthew

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: how to dynamically generate several file upload fields

Posted by matthew yee-king <ye...@no-future.com>.
> 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.
> 

that sounds like the best solution to me for the moment. I need a quick
solution as ever ;)

> 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:-)
> 


I'm thinking the best way would be to get into the taglibs and write
some new html: tags that let you generate sets of text fields or file
fields that are stored to an ActionForm's arrays in the same way you can
with the<html:select multiple="yes"..> tags. 

thanks for the tips

matthew

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: how to dynamically generate several file upload fields

Posted by Andrew Hill <an...@gridnode.com>.
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:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>