Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Struts2 + Dynamic Forms + File Upload

rakeshxp

2007-08-06



Hi,

I am trying to create a form which would have dynamic number of file tag (
this would be created by the JS ). I am looking for a way to do so in
struts.

I have created the following class
public class FileDetails {
  private File file;

  private String contentType;

  private String filename;

  public void setUpload(File file) {
    this.file = file;
  }

  public void setUploadContentType(String contentType) {
    this.contentType = contentType;
  }

  public void setUploadFileName(String filename) {
    this.filename = filename;
  }
}

And in my action class I am trying to do

private List<FileDetails> beanList = new ArrayList<FileDetails>();
  public List<FileDetails> getBeanList() {
    return beanList;
  }

  public void setBeanList(List<FileDetails> beanList) {
    this.beanList = beanList;
  }

And in the JSP,
<s:form namespace="/xyz" action="doUpload" method="post"
enctype="multipart/form-data">
  <s:file name="beanList(0).upload" value="%{value}" />    
  <s:file name="beanList(1).upload" value="%{value}" />    
   <s:submit/>
</s:form>

Above method does work as it results in lot of OGNL errors like
[ERROR] XWorkMethodAccessor - An unexpected exception occurred
<ognl.OgnlException: Error getting property descriptor:
null>ognl.OgnlException: E
rror getting property descriptor: null
    at
com.opensymphony.xwork2.util.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:92)
    at
com.opensymphony.xwork2.util.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:61)

Could any one suggest a solution to my problem ?
--
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.