2012-03-21 188 views
0

在Wicket頁面上,我有一個圖像(AbstractDefaultAjaxBehavior.INDICATOR),它在提交時顯示,然後我啓動一個AjaxSelfUpdatingTimerBehavior來監視文件。Wicket下載鏈接

現在我還有一個DownloadLink來下載同一個文件。然而,在下載之後,我上面提到的(正在旋轉的)圖像停止旋轉。有沒有解決這個問題的方法?我是新來的檢票口。請建議。

public LoggingPage() { 

Form<Void> form; 
    this.add(form = new Form<Void>("resourceForm") { 
     private static final long serialVersionUID = 1L; 

     @Override 
     protected void onSubmit() { 
      submit(); 
     } 
    }); 
    add(new DownloadLink("downloadButton", new AbstractReadOnlyModel<File>() 
    { 
     private static final long serialVersionUID = 1L; 

     @Override 
     public File getObject() 
     { 
      File file; 
      try 
      { 
       file = new File(LoggingPage.this.fileDetail.getLocation()); 
      } 
      catch (Exception e) 
      { 
       throw new RuntimeException(e); 
      } 
      return file; 
     } 
    })); 

}//cons ends 

private void submit() { 
    if (this.serverDetail != null && this.fileType != null && this.fileDetail != null) 
    { 
     if (this.fileViewer != null) 
     { 
      this.repeater.removeAll(); 
     } 
     File file = new File(this.fileDetail.getLocation()); 
     file = new File("C:/ueshome/logs/safe.log"); 
     this.fileViewer = new FileViewer(file); 
     this.fileViewer.startTailing(); 
     log.debug("load of allLog: " + this.fileViewer.getOldLog()); 
     buildItem(this.fileViewer.getOldLog().getLog().toString()); 
     this.container.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(1)) 
     { 
      @Override 
      protected void onPostProcessTarget(final AjaxRequestTarget target) 
      { 
       target.appendJavascript("$('#container').scrollTop(999999999)"); 
       log.debug("onPostProcessTarget: " + LoggingPage.this.fileViewer.hashCode() + "at: " + System.currentTimeMillis()); 
       final FileAttributes fileAttributes = LoggingPage.this.fileViewer.getNewLog(); 
       String newLog = fileAttributes.getLog().toString(); 
       log.debug("nextlog inside load()"); 
       if (newLog != null && newLog.trim().length() > 0) 
       { 
        log.debug("~~~~~~~~~~~~~~~~~~~~````*****:" + newLog); 
        log.debug("String.valueOf(fileAttributes.getSize()))~~~~~~~~~~~~~~~~~~~~````*****:" + String.valueOf(fileAttributes.getSize())); 
        log.debug("String.valueOf(fileAttributes.getLastModified()): " + String.valueOf(fileAttributes.getLastModified())); 

        if (LoggingPage.this.repeater.getSizeInBytes() >= logSize) 
        { 
         LoggingPage.this.repeater.removeAll(); 
        } 
        Component item = buildItem(newLog); 

        target.prependJavascript(String.format(
          "var item=document.createElement('%s');item.id='%s';Wicket.$('%s').appendChild(item);", 
          "div", item.getMarkupId(), LoggingPage.this.container.getMarkupId())); 

        //      LoggingPage.this.imgContainer.setVisible(true); 
        //      target.addComponent(LoggingPage.this.imgContainer); 
        target.addComponent(item); 

        target.appendJavascript("$('#fileAttributesContainer').show(); "); 
        target.appendJavascript("$('#container').scrollTop(999999999)"); 
        target.appendJavascript("$('#imageContainer').show(); "); 

       } 
       else 
       { 
        target.appendJavascript("$('#fileAttributesContainer').show(); "); 
        target.appendJavascript("$('#container').scrollTop(999999999)"); 
        target.appendJavascript("$('#imageContainer').show(); "); 
       } 

       target.appendJavascript("alert('You are in Ajax Self')"); 
      } 
+1

你能舉一個你的代碼樣本嗎? – magomi 2012-03-21 06:45:07

+0

我已添加示例代碼。感謝您的快速回復。 – user1521828 2012-03-21 18:41:03

+1

將來,在添加代碼時,只需編輯您的問題,而不是將它發佈在答案中。 – Wilduck 2012-03-22 14:30:46

回答

1

首先,我不得不承認,我現在不知道你的代碼有什麼問題。它看起來不像我會如何解決你的任務。

據我所知,你想有一個圖像(動畫gif),在用戶點擊提交按鈕後動畫。在滿足一定的條件(文件生成完成等)後,應該停止動畫。你也想爲你的文件有一個下載鏈接。

我會做的是

  • 使用GIF動畫,將顯示
  • 添加AjaxSelfUpdatingTimerBehavior,檢查你的文件,如果一定條件滿足它改變了圖像(可能通過改變圖像本身,設置圖像的可見性或通過更改圖像容器的一些css屬性)
  • 用於文件下載我將使用ajax按鈕,或者如果您身邊沒有任何東西應該改變爲提供資源流的正常鏈接你的檔案

希望這有助於一點點。

+0

感謝您的建議,我相信這些工作。 – user1521828 2012-03-22 20:29:39

+0

你能否提供一些上述第3點的示例代碼(對於文件下載,我將使用ajax按鈕或者如果沒有什麼應該在你身邊改變爲你的文件提供資源流的普通鏈接 ) – user1521828 2012-03-23 01:38:58

+0

對不起,回答。 我在github上提供了一個簡單的例子:https://github.com/magomi/wicket-download-sample 它提供了一個標籤和一個下載鏈接。當你點擊鏈接時,下載將開始,標籤將通過ajax進行更改。這個(AjaxDownloadBehavior)的核心部分記錄在wicket wiki中:https://cwiki.apache.org/WICKET/ajax-update-and-file-download-in-one-blow.html – magomi 2012-03-25 07:17:12