I am having a problem using indexed properties.
In my ActionForm I have the following:
private List files = new ArrayList();
public FileForm[] getFiles() { return (FileForm[])files.toArray(new FileForm[files.size()]); }
public FileForm getFiles(int index){ return (FileForm)files.get(index); }
public void setFiles(FileForm[] files) { this.files = new ArrayList(Arrays.asList(files)); }
public void setFiles(int index, FileForm file){ this.files.add(index, file); }
The FileForm class is just a standard bean
public class FileForm implements Serializable {
private String name; private int size; private String path;
public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public int getSize() { return size; } public void setSize(int size) { this.size = size; } }
If I add one file it appears to work fine, my action adds the file info to the form and the results is as I'd expect.
<tr>
<td><input type="hidden" name="files[0].name" value="goods.xml">goods.xml</td>
<td><input type="hidden" name="files[0].size" value="3650971">3650971</td> </tr>
but when I then resubmit the form I get the following exception. It appears to me it is trying to get the files before setting them.
500 Servlet Exception
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:507)
at java.util.ArrayList.get(ArrayList.java:324)
at nz.co.apackage.struts.form.EmailForm.getFiles(EmailForm.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:493)
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:798)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:205)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:165)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:113)
at com.netbyte.hibernate.PersistanceFilter.doFilter(PersistanceFilter.java:89)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:84)
at com.netbyte.auth.AuthFilter.doFilter(AuthFilter.java:75)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:84)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:177)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
at java.lang.Thread.run(Thread.java:534)
I'm using Resin EE 3.0.8 and Struts 1.2.4. Could somebody please shed some light on what I'm doing wrong. I've tried several different configuration for my indexed field in the form bean including exposing the list and having a standard array rather that a list backed array but I get the same exception.
_________________________________________________________________ Check out news, entertainment and more @ http://xtra.co.nz/broadband
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]