I'm using Struts2 2.5.20 and have written a file upload action that almost works. I can see in the debugger that setReport(), setReportContentType() and setReportFileName() are being called and the parameter values are correct. However, the execute() method is never invoked. I tried following the call stack to see where it should have been called, but there's just layer after layer of interceptors that I can't find the bottom.
Does anyone know what the reason for execute() might be?
public class ImportReportAction extends CampaignerActionSupport implements ValidationAware
{
private File report;
private String reportContentType;
private String reportFileName;
@Override
public String execute() throws Exception
{
...
return SUCCESS;
}
public void setReport(
File report)
{
this.report = report;
}
public void setReportContentType(
String reportContentType)
{
this.reportContentType = reportContentType;
}
@RequiredFieldValidator(type = ValidatorType.FIELD, key = "errors.required", messageParams = { "getText('labels.report.file')" })
public void setReportFileName(
String reportFileName)
{
this.reportFileName = reportFileName;
}
}
Update: I've discovered that the problem is in having the RequiredFieldValidator annotation. When that is present, the validation always fails but the s:actionerror tag is not displaying any message. When the annotation is not present, it allows a user to not pick a file and still calls execute().
The new question is: how to I correctly annotate my class for validation of a file upload?