aspose file tools*
The moose likes Struts and the fly likes Struts.. file upload array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts.. file upload array" Watch "Struts.. file upload array" New topic
Author

Struts.. file upload array

Joe Koppole
Greenhorn

Joined: Nov 26, 2007
Posts: 6
Hi,
I am using a bean to dynamically get populate no of file uploads in a page from the bean.

The HTML is getting generated as

In the the Form Class


In the action class when i try to retrieve the data from
It is giving null. Can some one help me where I am going wrong.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
When using indexed properties you must provide an indexed getter and setter, which you have not. You must also initialize the array to the number of elements you expect. If you don't know how many elements, use a java.util.List instead of an array. Also, indexed="true" works only for an array or list of JavaBeans, not for a simple array. For a simple array, you have to build the the indexed property name yourself. Example:

new accessors:

new JSP entry:


Merrill
Consultant, Sima Solutions
Joe Koppole
Greenhorn

Joined: Nov 26, 2007
Posts: 6
Thanks Merrill,
It did work. But was a little curious about the usage of List. Can you give me some pointer how to use it. The number of components is dynamic and is not restricted.

Thanks
Joe
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Tekkie Joe,

I'm glad it worked.

Before we go any further, though, one of my duties as forum moderator is to see that the guidelines are followed, and I noticed the name you are currently displaying does not meet the guidelines of the JavaRanch Naming Policy. In particular, the name you display must be a first and last name, and must not be obviously fictitious. Please change the Publicly Displayed Name in your user profile so that it meets the guidelines.

This may seem trivial to you, but it's an important part of the culture at JavaRanch, and we do appreciate your compliance with it.

Regarding your question about using a List, you would just change the underlying representation of customDocs variable from an array to a List. You would then modify the getter and setter accordingly. You would also have to give your accessors "lazy initialization" behavior. For more information and an example of this, see question 6 of this forum's FAQ.
Joe Koppole
Greenhorn

Joined: Nov 26, 2007
Posts: 6
Well Merrill, Thanks.. Well Just added a caption as usual. Didn't know that it will create problems any way changed it Thanks for your help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts.. file upload array
 
Similar Threads
html:form enctype="multipart/form-data"
uploading multi images by using file upload...
problem in logic:iterate
Struts 1.2.4 File Upload - Form File is null in action
Displaying file content in a jsp page