[英]Struts2 file upload - execute() is not being invoked
I'm using Struts2 2.5.20 and have written a file upload action that almost works.我正在使用 Struts2 2.5.20 并编写了一个几乎可以工作的文件上传操作。 I can see in the debugger that setReport(), setReportContentType() and setReportFileName() are being called and the parameter values are correct.我可以在调试器中看到正在调用 setReport()、setReportContentType() 和 setReportFileName() 并且参数值是正确的。 However, the execute() method is never invoked.然而,execute() 方法永远不会被调用。 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?有谁知道 execute() 的原因可能是什么?
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.更新:我发现问题在于具有 RequiredFieldValidator 注释。 When that is present, the validation always fails but the s:actionerror tag is not displaying any message.当它存在时,验证总是失败,但 s:actionerror 标记不显示任何消息。 When the annotation is not present, it allows a user to not pick a file and still calls execute().当注释不存在时,它允许用户不选择文件并仍然调用 execute()。
The new question is: how to I correctly annotate my class for validation of a file upload?新问题是:如何正确注释我的类以验证文件上传?
我必须删除 @RequiredFieldValidator 注释,使我的操作实现 ValidationAware,然后实现一个 validate() 方法并手动将验证放在那里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.