Reputation: 5518
I have the following in my Struts ActionForm
private List<FormFile> attachmentList = new ArrayList<FormFile>();
public MyForm() {
for (int i = 0 ; i < 5 ; i++) {
getAttachmentList().add(null);
}
}
public List<FormFile> getAttachmentList() {
return attachmentList;
}
public void setAttachmentList(List<FormFile> attachmentList) {
this.attachmentList = attachmentList;
}
public FormFile getAttachmentList(int index) {
return getAttachmentList().get(index);
}
public void setAttachmentList(int index, FormFile formFile) {
getAttachmentList().set(index, formFile);
}
And in my JSP I have the following
<c:forEach var="counter" begin="0" end="4">
<input type="file" name="attachmentList[${counter}]" size="50" />
</c:forEach>
Everything works fine, unless the validate
method of the ActionForm
finds errors (usually related to other fields on the form). When the form reloads, the file inputs are no longer populated. I added an assert right before the display Action
returns the reloaded page, and the ActionForm
has the right number of attachments (their file names are not blank etc).
Does anyone know how to make the files bind and stay?
Upvotes: 1
Views: 696
Reputation: 160251
File fields cannot be pre-filled; this is a well-known browser thing and has nothing to do with Struts.
Upvotes: 2