0

I am creating a report download form in GWT. Downloading report document takes 2-3 minutes and I am opening it in new tab, but new tab is blank and waiting for the server response. Now I want to display some custom message like "File is downloading, don't close this tab". How to do this in GWT? My current code is like below which open blank page with URL..

FormPanel m_downloadForm = new FormPanel();
m_downloadForm.setMethod(FormPanel.METHOD_POST);
m_downloadForm.setAction(url);
m_downloadForm.getElement().<FormElement>cast().setTarget("_blank");
Hidden h = new Hidden();
h.setName("OkBtn"    );
h.setID(  "OkBtn"    );
h.setValue("Create Report");
m_downloadForm.add(h);
m_rootContent.add(m_downloadForm);

This code opens new tab with no message successfully and document is being downloaded. I want to display some message on new tab.

Pandey Amit
  • 657
  • 6
  • 19
  • I just want to display a custom message instead of blank on new tab between request and response. How to achieve that ? – Pandey Amit Oct 24 '17 at 09:52

2 Answers2

0

You need to use another thread for downloading. Your program currently uses only one thread. Which means your program is running sequentially. It needs to finish executing whatever is being executed before doing any thing else. Having multiple threads makes tasks being executed in parallel.

  • opening new tab on browser is same as spawning new thread which is responsible for receiving response. I just want to display message on new tab between request and response. How to achieve that ? – Pandey Amit Oct 24 '17 at 09:51
  • Browsers don't have threads that you can interact with, at least not in the way you seem to be suggesting. Instead, IO is already done off thread, and you respond to it with callbacks or event handlers. – Colin Alworth Oct 25 '17 at 18:16
0

You are using native browser methods to open the report: sending the url via a form to a new browser window. From that point on you have no more control over what is shown and how the users expectations are managed.

What you could do is create a small GWT wrapper page that has a Frame in it. Inside that frame you would be loading the report that the user requested. The wrapper GWT page shows an info-screen informing the user that they need to be patient. It then checks if/when the report is actually done downloading / rendering and as soon as this is the case removes the info-screen so that the Frame is actually full-screen.

  1. First of course, you would need to create a wrapper. It would be a small new html page with a GWT moduleloader. The GWT module creates a panel to contain the info-message and the iFrame.

  2. You would need some way to get the report that the user requested to be passed to the GWT wrapper page. You could pass the requested report to your wrapper using a url query parameter. Something like this: http://www.yourdomain.com/reportwaitscreenapp.html?reporttoload=http://www.yourreportserver.com/repot5.xml\amp&;parameter1=5

  3. Then in reportwaitscreenapp figure out what the reporttoload is using Window.Location. And pass that to the Frame to load.

  4. Then create a Frame (or a PDF object, Image, etc.) in which you load the report.

  5. Check status. This is going to be tough and will depend on what kind of object you are trying to load and what browsers you are using. You can try the Frame.onLoad() method, but I've read that in some situations it just fires immediatly and doesn't wait until the download is finished.

Are you trying to load a PDF and you want the browsers pdf viewer? Or regular html and use a (i)Frame? This page has some discussion about how you could check if a Frame is done loading/rendering.

  1. Remove your please-wait message.

This will probably be a lot of trial and error.

prinsarian
  • 31
  • 3