当用户在GWTUpload中删除上传的图像时,在哪里调用Action?

时间:2014-09-30 09:37:57

标签: gwt gwtupload

我正在使用GWTUpload,库在这里https://code.google.com/p/gwtupload/

在该网站上找到的客户端示例代码具有以下结构:

 // Attach an image to the pictures viewer
private OnLoadPreloadedImageHandler showImage = new OnLoadPreloadedImageHandler() {
    public void onLoad(PreloadedImage image) {
      //showImageFlowPanel code solution 1
      image.setWidth("75px");
      showImageFlowPanel.add(image);
    }
};


private IUploader.OnFinishUploaderHandler onFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
      public void onFinish(IUploader uploader) {
        if (uploader.getStatus() == Status.SUCCESS) {

          new PreloadedImage(uploader.fileUrl(), showImage);

          UploadedInfo info = uploader.getServerInfo();

          String headShotImageUrl="http://"+Window.Location.getHost()+"/" +"images/uploaded/"+info.message;
          //headShotImage code solution 2
          if(!"".equals(headShotImageUrl) && UriUtils.isSafeUri(headShotImageUrl)){
              headShotImage.setUrl(UriUtils.fromString(headShotImageUrl));
          }



        }
      }
    };

该示例使用showImageFlowPanel(解决方案1)来存储图像,但我想将图像存储在headShotImage内,并在用户上传图像成功后获取网址,请参阅headShotImage(解决方案2)上面的代码。

好的,headShotImage代码工作正常但我不知道如何在用户删除图像时将其删除。如果我在解决方案1中使用showImageFlowPanel,那么程序会自动删除图像,我不需要做任何事情。

所以我的问题是“当用户在GWTUpload中删除上传的图像时,在何处调用操作?

1 个答案:

答案 0 :(得分:1)

您必须使用setOnCancelUploaderHandler。看一下从演示中获取的代码。

// When the user clicks a cancel button we get an event
uploader.addOnCancelUploadHandler ( 
  new IUploader.OnCancelUploaderHandler() {
    public void onCancel(IUploader uploader) {
      for (String iname : uploader.getServerMessage().getUploadedFieldNames()) {
        // loadedImages is an temporary table where we are adding all uploaded files
        // indexed by field name
        Widget w = loadedImages.get(iname);
        if (w != null) {
          w.removeFromParent();
        loadedImages.remove(uploader.getInputName());
       }
     }
   }
});