Frage

I'm trying to set the FileUploadInterceptor on an action by annotation :

@Namespace("/")
@ParentPackage("my-package")
@Result(name = "success", location = "/WEB-INF/jsp/result.jsp")
@InterceptorRef("fileUpload")
public class UploadAction extends ActionSupport {

  private File upload;
  private String uploadContentType;
  private String uploadFileName;

  public void setUpload(File upload) {
    this.upload = upload;
  }
  public void setUploadContentType(String uploadContentType) {
    this.uploadContentType = uploadContentType;
  }
  public void setUploadFileName(String uploadFileName) {
    this.uploadFileName = uploadFileName;
  }
  public File getUpload() {
    return this.upload;
  }
  public String getUploadContentType() {
    return this.uploadContentType;
  }
  public String getUploadFileName() {
    return this.uploadFileName;
  }
  @Override
  @Action("doUpload")
  public String execute()
  {
    System.out.println("Upload ok : " + (this.upload != null));
    return SUCCESS;
  }
}

My issue is that it works only if I don't set ANY interceptor on the action class. As soon as I set an interceptor, even FileUploadInterceptor like above, the attribute are not filled.

Basicaly, this works :

public class UploadAction extends ActionSupport {...

But this DOESN'T work :

@InterceptorRefs({
  @InterceptorRef("fileUpload")
})
public class UploadAction extends ActionSupport {...

or

@InterceptorRefs({
  @InterceptorRef("fileUpload"),
  @InterceptorRef("myOtherinterceptor")
})
public class UploadAction extends ActionSupport {...

I found ! The solution is :

@InterceptorRefs({
  @InterceptorRef("fileUpload"),
  @InterceptorRef("basicStack")
})
public class UploadAction extends ActionSupport {...
War es hilfreich?

Lösung

If you set any interceptor, you must set all interceptors. Basically you're turning off all but the upload interceptor, which isn't what you want.

If you are going to manually configure interceptors, and need to refer to multiple interceptors, use the @InterceptorRefs "wrapper" annotation as per the InterceptorRef docs.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top