0

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?

Gary Kephart
  • 4,860
  • 5
  • 39
  • 52
  • An interceptor puking between the request and the action--likely a validation or filesize. But there's little else to say with the information provided. – Dave Newton Feb 17 '20 at 16:11
  • I wish there was more information to give you. There's nothing in any log file. I'd think that if some interceptor was failing, there would be something in a log file or on the screen, but there isn't. I agree, though, despite that, that an interceptor might be the problem. – Gary Kephart Feb 18 '20 at 14:44
  • Then turn up logging, or look harder at the stack trace in the debugger--there's a finite number of interceptors, and they run in a known order. – Dave Newton Feb 18 '20 at 14:57
  • https://stackoverflow.com/a/16017115/573032 – Roman C Feb 20 '20 at 05:30

1 Answers1

0

I had to remove the @RequiredFieldValidator annotation, make my action implement ValidationAware and then implement a validate() method and manually put the validations in there.

Gary Kephart
  • 4,860
  • 5
  • 39
  • 52