user1521828
user1521828

Reputation: 57

Wicket download link

On the Wicket page I have an image (AbstractDefaultAjaxBehavior.INDICATOR) which is shown on submit and then i start a AjaxSelfUpdatingTimerBehavior to monitor a file.

Now I also have a DownloadLink to download the same file. However after download the image which I mentioned above (which is rotating) stops rotating. Is there a solution to this issue? I am new to wicket. Please suggest.

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

Upvotes: 0

Views: 3052

Answers (1)

magomi
magomi

Reputation: 6685

First I have to admit that I have no idea right now what could be wrong with your code. It looks rather different than how I would solve your task.

As I understand you want to have a image (an animated gif) that is animated after the user hits the submit button, right. And it should stop the animation after a certain condition is met (file generation finished etc.). Also you want to have a download link for your file.

What I would do is

  • use a animated gif that will be shown
  • add a AjaxSelfUpdatingTimerBehavior that checks your file and if a certain condition is met it changes the image (maybe by changing the image itself, sets the visibility of the image or by changing some css attribute for the image container)
  • for the file download I would use an ajax button or if nothing should be changed on your side a normal link that delivers an resource stream for your file

Hope this helps a little bit.

Upvotes: 1

Related Questions