Wicket下载链接



在Wicket页面上,我有一个提交时显示的图像(AbstractDefaultAjaxBehavior.INDICATOR),然后我启动AjaxSelfUpdatingTimerBehavior来监视文件。

现在我也有一个下载链接来下载相同的文件。然而,下载后,我上面提到的图像(正在旋转)停止旋转。这个问题有解决办法吗?我是初来乍到的。请提出建议。

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')");
            }

首先我必须承认,我现在不知道您的代码可能出了什么问题。这看起来与我解决你任务的方式大不相同。

据我所知,你想要一张在用户点击提交按钮后设置动画的图像(动画gif),对吧。它应该在满足特定条件后停止动画(文件生成完成等)。此外,你还想有一个文件的下载链接。

我会做的是

  • 使用将显示的动画gif
  • 添加一个AjaxSelfUpdatingTimerBehavior,它会检查你的文件,如果满足某个条件,它会更改图像(可能是通过更改图像本身、设置图像的可见性或更改图像容器的一些css属性)
  • 对于文件下载,我会使用ajax按钮,或者如果您这边没有任何更改,则使用一个普通的链接为您的文件提供资源流

希望这能有所帮助。

最新更新