Out-of-sync error after download prompt

Hello,

I’ve been getting a very annoying Out-of-sync error for a while now and I can’t seem to find a useful solution. I have tried a lot of solutions found on the internet but neither of them helped me out. The error occurs after I open a FileResource with either _top or _self, the error doesn’t occur on _blank. After I opened, saved or cancelled the file in the download prompt I can’t seem to be able to click anything within my application without getting the error.

Here’s the related code:

public void run() {
                MyApp.setInstance(app);
                try {
                    File file = 
                        new PrognosesCSVWriter(selectedRound).generateCSVFile(indicator);

                    synchronized(MyApp.getInstance()) {
                        MyApp.getMainWindow().open(new FileResource(file, 
                                MyApp.getInstance()));
                        file.deleteOnExit();
                    }
                }
                catch (IOException e) {
                    e.printStackTrace();
                }

                isProgressing = false;

                synchronized(MyAppgetInstance()) {
                   MyApp.getInstance().onRequestEnd(null, null);
                    layout.removeComponent(indicator);
                }
            }
        };

Thanks in advance!

You simply cannot provide a file to download and update your client side in one request.

So, is there anyway I can provide a generated file to download without getting out of sync? Should I be generating the file on the first button click and let the user press to actually download it or is there a way to do this in one step?

Is there anyone who knows how to open a FileResource without using “_blank” parameter and not getting the out-of-sync error? I can’t seem to find a working solution…

May I ask what you want to achieve?

If you want to show the file inside your application you could use an Embedded object with your resource as source.

I want to show a window (like the example below) where a user can choose whether he wants to open or save the generated file. But the problem is that when I use getMainWindow().open(FileResource) the client gets out-of-sync after the window is being shown. The only way I can fix it is by adding the _blank parameter but the browser will block the download window in that case which I don’t want to.

You have to create a subclass of the FileResource class where you overwrite the getStream() method:

@Override
public DownloadStream getStream()
{
  DownloadStream stream = super.getStream();
  if(stream!=null)
  {
    stream.setParameter("Content-Disposition", "attachment;filename=\"" + getFilename()+ "\"");
  }
  return stream;
}

You can do the override using an anonymous inner class as well

FileResource fr = new FileResource(){
    @Override
    public DownloadStream getStream() {
       ...
    });

to avoid creating a new java file.

Thanks for the answers, but unfortunately I still get the out-of-sync error using the FileResource override… :frowning: